1 `include "ARM_Constants.v"
10 output reg [31:0] busaddr,
14 output reg [31:0] wr_data,
16 output reg [2:0] data_size,
18 /* regfile interface */
19 output reg [3:0] st_read,
22 /* Coprocessor interface */
26 output reg cp_rnw, /* 1 = read from CP, 0 = write to CP */
28 output reg [31:0] cp_write,
40 input [3:0] write_num,
41 input [31:0] write_data,
46 output reg [31:0] outpc,
47 output reg [31:0] outinsn,
48 output reg out_write_reg = 1'b0,
49 output reg [3:0] out_write_num = 4'bxxxx,
50 output reg [31:0] out_write_data = 32'hxxxxxxxx,
51 output reg [31:0] outspsr = 32'hxxxxxxxx,
52 output reg [31:0] outcpsr = 32'hxxxxxxxx
55 reg [31:0] addr, raddr, prev_raddr, next_regdata, next_outcpsr;
57 reg [3:0] next_regsel, cur_reg, prev_reg;
62 reg [3:0] next_write_num;
63 reg [31:0] next_write_data;
65 reg [1:0] lsr_state = 2'b01, next_lsr_state;
66 reg [31:0] align_s1, align_s2, align_rddata;
68 reg [1:0] lsrh_state = 2'b01, next_lsrh_state;
69 reg [31:0] lsrh_rddata;
70 reg [15:0] lsrh_rddata_s1;
71 reg [7:0] lsrh_rddata_s2;
73 reg [15:0] regs, next_regs;
74 reg [2:0] lsm_state = 3'b001, next_lsm_state;
75 reg [5:0] offset, prev_offset, offset_sel;
77 reg [31:0] swp_oldval, next_swp_oldval;
78 reg [1:0] swp_state = 2'b01, next_swp_state;
84 outbubble <= next_outbubble;
85 out_write_reg <= next_write_reg;
86 out_write_num <= next_write_num;
87 out_write_data <= next_write_data;
90 prev_offset <= offset;
92 outcpsr <= next_outcpsr;
94 swp_state <= next_swp_state;
95 lsm_state <= next_lsm_state;
96 lsr_state <= next_lsr_state;
97 lsrh_state <= next_lsrh_state;
104 raddr = 32'hxxxxxxxx;
107 wr_data = 32'hxxxxxxxx;
108 busaddr = 32'hxxxxxxxx;
111 next_write_reg = write_reg;
112 next_write_num = write_num;
113 next_write_data = write_data;
114 next_outbubble = inbubble;
118 cp_write = 32'hxxxxxxxx;
119 offset = prev_offset;
120 next_outcpsr = lsm_state == 3'b010 ? outcpsr : cpsr;
121 lsrh_rddata = 32'hxxxxxxxx;
122 lsrh_rddata_s1 = 16'hxxxx;
123 lsrh_rddata_s2 = 8'hxx;
124 next_lsm_state = lsm_state;
125 next_lsr_state = lsr_state;
126 next_lsrh_state = lsrh_state;
127 next_swp_oldval = swp_oldval;
128 next_swp_state = swp_state;
131 /* XXX shit not given about endianness */
133 next_outbubble = 1'b1;
135 `DECODE_ALU_SWP: if(!inbubble) begin
137 next_outbubble = rw_wait;
138 busaddr = {op0[31:2], 2'b0};
139 data_size = insn[22] ? 3'b001 : 3'b100;
145 next_swp_state = 2'b10;
146 next_swp_oldval = rd_data;
151 wr_data = insn[22] ? {4{op1[7:0]}} : op1;
152 next_write_reg = 1'b1;
153 next_write_num = insn[15:12];
154 next_write_data = insn[22] ? {24'b0, swp_oldval[7:0]} : swp_oldval;
156 next_swp_state = 2'b01;
161 `DECODE_ALU_HDATA_REG,
162 `DECODE_ALU_HDATA_IMM: if(!inbubble) begin
163 next_outbubble = rw_wait;
165 addr = insn[23] ? op0 + op1 : op0 - op1; /* up/down select */
166 raddr = insn[24] ? op0 : addr; /* pre/post increment */
168 /* rotate to correct position */
170 2'b00: begin end /* swp */
171 2'b01: begin /* unsigned half */
172 wr_data = {2{op2[15:0]}}; /* XXX need to store halfword */
174 lsrh_rddata = {16'b0, raddr[1] ? rd_data[31:16] : rd_data[15:0]};
176 2'b10: begin /* signed byte */
177 wr_data = {4{op2[7:0]}};
179 lsrh_rddata_s1 = raddr[1] ? rd_data[31:16] : rd_data[15:0];
180 lsrh_rddata_s2 = raddr[0] ? lsrh_rddata_s1[15:8] : lsrh_rddata_s1[7:0];
181 lsrh_rddata = {{24{lsrh_rddata_s2[7]}}, lsrh_rddata_s2};
183 2'b11: begin /* signed half */
184 wr_data = {2{op2[15:0]}};
186 lsrh_rddata = raddr[1] ? {{16{rd_data[31]}}, rd_data[31:16]} : {{16{rd_data[15]}}, rd_data[15:0]};
194 next_write_num = insn[15:12];
195 next_write_data = lsrh_rddata;
197 next_write_reg = 1'b1;
199 if(insn[21] | !insn[24]) begin
202 next_lsrh_state = 2'b10;
206 next_write_reg = 1'b1;
207 next_write_num = insn[19:16];
208 next_write_data = addr;
209 next_lsrh_state = 2'b10;
214 `DECODE_LDRSTR_UNDEFINED: begin end
215 `DECODE_LDRSTR: if(!inbubble) begin
216 next_outbubble = rw_wait;
218 addr = insn[23] ? op0 + op1 : op0 - op1; /* up/down select */
219 raddr = insn[24] ? op0 : addr; /* pre/post increment */
221 /* rotate to correct position */
222 align_s1 = raddr[1] ? {rd_data[15:0], rd_data[31:16]} : rd_data;
223 align_s2 = raddr[0] ? {align_s1[7:0], align_s1[31:8]} : align_s1;
224 /* select byte or word */
225 align_rddata = insn[22] ? {24'b0, align_s2[7:0]} : align_s2;
226 wr_data = insn[22] ? {4{op2[7:0]}} : op2; /* XXX need to actually store just a byte */
227 data_size = insn[22] ? 3'b001 : 3'b100;
232 next_write_reg = 1'b1;
233 next_write_num = insn[15:12];
235 next_write_data = align_rddata;
237 if(insn[21] | !insn[24]) begin
240 next_lsr_state = 2'b10;
244 next_write_reg = 1'b1;
245 next_write_num = insn[19:16];
246 next_write_data = addr;
247 next_lsr_state = 2'b10;
252 /* XXX ldm/stm incorrect in that stupid case where one of the listed regs is the base reg */
253 `DECODE_LDMSTM: if(!inbubble) begin
255 next_outbubble = rw_wait;
259 // next_regs = insn[23] ? op1[15:0] : op1[0:15];
260 /** verilator can suck my dick */
261 next_regs = insn[23] ? op1[15:0] : {op1[0], op1[1], op1[2], op1[3], op1[4], op1[5], op1[6], op1[7],
262 op1[8], op1[9], op1[10], op1[11], op1[12], op1[13], op1[14], op1[15]};
265 next_lsm_state = 3'b010;
271 16'b???????????????1: begin
273 next_regs = {regs[15:1], 1'b0};
275 16'b??????????????10: begin
277 next_regs = {regs[15:2], 2'b0};
279 16'b?????????????100: begin
281 next_regs = {regs[15:3], 3'b0};
283 16'b????????????1000: begin
285 next_regs = {regs[15:4], 4'b0};
287 16'b???????????10000: begin
289 next_regs = {regs[15:5], 5'b0};
291 16'b??????????100000: begin
293 next_regs = {regs[15:6], 6'b0};
295 16'b?????????1000000: begin
297 next_regs = {regs[15:7], 7'b0};
299 16'b????????10000000: begin
301 next_regs = {regs[15:8], 8'b0};
303 16'b???????100000000: begin
305 next_regs = {regs[15:9], 9'b0};
307 16'b??????1000000000: begin
309 next_regs = {regs[15:10], 10'b0};
311 16'b?????10000000000: begin
313 next_regs = {regs[15:11], 11'b0};
315 16'b????100000000000: begin
317 next_regs = {regs[15:12], 12'b0};
319 16'b???1000000000000: begin
321 next_regs = {regs[15:13], 13'b0};
323 16'b??10000000000000: begin
325 next_regs = {regs[15:14], 14'b0};
327 16'b?100000000000000: begin
329 next_regs = {regs[15], 15'b0};
331 16'b1000000000000000: begin
340 cur_reg = insn[23] ? 4'hF - cur_reg : cur_reg;
341 if(cur_reg == 4'hF && insn[22]) begin
351 offset = prev_offset + 6'h4;
352 offset_sel = insn[24] ? offset : prev_offset;
353 raddr = insn[23] ? op0 + {26'b0, offset_sel} : op0 - {26'b0, offset_sel};
355 next_write_reg = 1'b1;
356 next_write_num = cur_reg;
357 next_write_data = rd_data;
367 if(next_regs == 16'b0) begin
368 next_lsm_state = 3'b100;
372 next_write_reg = 1'b1;
373 next_write_num = insn[19:16];
374 next_write_data = insn[23] ? op0 + {26'b0, prev_offset} : op0 - {26'b0, prev_offset};
375 next_lsm_state = 3'b001;
380 `DECODE_LDCSTC: if(!inbubble) begin
381 $display("WARNING: Unimplemented LDCSTC");
383 `DECODE_CDP: if(!inbubble) begin
390 /* XXX undefined instruction trap */
391 $display("WARNING: Possible CDP undefined instruction");
394 `DECODE_MRCMCR: if(!inbubble) begin
396 cp_rnw = insn[20] /* L */;
397 if (insn[20] == 0 /* store to coprocessor */)
400 if (insn[15:12] != 4'hF /* Fuck you ARM */) begin
401 next_write_reg = 1'b1;
402 next_write_num = insn[15:12];
403 next_write_data = cp_read;
405 next_outcpsr = {cp_read[31:28], cpsr[27:0]};
412 $display("WARNING: Possible MRCMCR undefined instruction: cp_ack %d, cp_busy %d",cp_ack, cp_busy);
414 $display("MRCMCR: ack %d, busy %d", cp_ack, cp_busy);