1 `include "ARM_Constants.v"
8 output reg [31:0] busaddr,
12 output reg [31:0] wr_data,
15 /* regfile interface */
16 output reg [3:0] st_read,
19 /* Coprocessor interface */
23 output cp_rnw, /* 1 = read from CP, 0 = write to CP */
25 output reg [31:0] cp_write,
37 input [3:0] write_num,
38 input [31:0] write_data,
43 output reg [31:0] outpc,
44 output reg [31:0] outinsn,
45 output reg out_write_reg = 1'b0,
46 output reg [3:0] out_write_num = 4'bxxxx,
47 output reg [31:0] out_write_data = 32'hxxxxxxxx,
48 output reg [31:0] out_spsr = 32'hxxxxxxxx,
49 output reg [31:0] out_cpsr = 32'hxxxxxxxx
52 reg [31:0] addr, raddr, prev_raddr, next_regdata, next_outcpsr;
53 reg [3:0] next_regsel, cur_reg, prev_reg;
55 reg [31:0] align_s1, align_s2, align_rddata;
59 wire [3:0] next_write_num;
60 wire [31:0] next_write_data;
62 reg [1:0] lsr_state = 2'b01, next_lsr_state;
64 reg [15:0] regs, next_regs;
65 reg [2:0] lsm_state = 3'b001, next_lsm_state;
66 reg [5:0] offset, prev_offset, offset_sel;
68 reg [31:0] swp_oldval, next_swp_oldval;
69 reg [1:0] swp_state = 2'b01, next_swp_state;
75 outbubble <= next_outbubble;
76 out_write_reg <= next_write_reg;
77 out_write_num <= next_write_num;
78 out_write_data <= next_write_data;
81 prev_offset <= offset;
83 out_cpsr <= next_outcpsr;
85 swp_state <= next_swp_state;
94 wr_data = 32'hxxxxxxxx;
95 busaddr = 32'hxxxxxxxx;
97 next_write_reg = write_reg;
98 next_write_num = write_num;
99 next_write_data = write_data;
100 next_outbubble = inbubble;
105 cp_write = 32'hxxxxxxxx;
106 offset = prev_offset;
107 next_outcpsr = lsm_state == 3'b010 ? out_cpsr : cpsr;
108 next_lsm_state = lsm_state;
109 next_lsr_state = lsr_state;
110 next_swp_oldval = swp_oldval;
111 next_swp_state = swp_state;
114 /* XXX shit not given about endianness */
117 `DECODE_ALU_SWP: if(!inbubble) begin
119 next_outbubble = rw_wait;
120 busaddr = {op0[31:2], 2'b0};
126 next_swp_state = 2'b10;
127 next_swp_oldval = rd_data;
133 next_write_reg = 1'b1;
134 next_write_num = insn[15:12];
135 next_write_data = swp_oldval;
137 next_swp_state = 2'b01;
142 `DECODE_LDRSTR_UNDEFINED: begin end
143 `DECODE_LDRSTR: if(!inbubble) begin
144 next_outbubble = rw_wait;
146 addr = insn[23] ? op0 + op1 : op0 - op1; /* up/down select */
147 raddr = insn[24] ? op0 : addr; /* pre/post increment */
148 busaddr = {raddr[31:2], 2'b0};
149 /* rotate to correct position */
150 align_s1 = raddr[1] ? {rd_data[15:0], rd_data[31:16]} : rd_data;
151 align_s2 = raddr[0] ? {align_s1[7:0], align_s1[31:8]} : align_s1;
152 /* select byte or word */
153 align_rddata = insn[22] ? {24'b0, align_s2[7:0]} : align_s2;
155 wr_data = insn[22] ? {4{op2[7:0]}} : op2; /* XXX need to actually store just a byte */
162 next_write_reg = 1'b1;
163 next_write_num = insn[15:12];
164 next_write_data = align_rddata;
169 next_lsr_state = 2'b10;
173 next_write_reg = 1'b1;
174 next_write_num = insn[19:16];
175 next_write_data = addr;
176 next_lsr_state = 2'b10;
181 /* XXX ldm/stm incorrect in that stupid case where one of the listed regs is the base reg */
182 `DECODE_LDMSTM: if(!inbubble) begin
184 next_outbubble = rw_wait;
187 // next_regs = insn[23] ? op1[15:0] : op1[0:15];
188 /** verilator can suck my dick */
189 next_regs = insn[23] ? op1[15:0] : {op1[0], op1[1], op1[2], op1[3], op1[4], op1[5], op1[6], op1[7],
190 op1[8], op1[9], op1[10], op1[11], op1[12], op1[13], op1[14], op1[15]};
193 next_lsm_state = 3'b010;
199 16'b???????????????1: begin
201 next_regs = {regs[15:1], 1'b0};
203 16'b??????????????10: begin
205 next_regs = {regs[15:2], 2'b0};
207 16'b?????????????100: begin
209 next_regs = {regs[15:3], 3'b0};
211 16'b????????????1000: begin
213 next_regs = {regs[15:4], 4'b0};
215 16'b???????????10000: begin
217 next_regs = {regs[15:5], 5'b0};
219 16'b??????????100000: begin
221 next_regs = {regs[15:6], 6'b0};
223 16'b?????????1000000: begin
225 next_regs = {regs[15:7], 7'b0};
227 16'b????????10000000: begin
229 next_regs = {regs[15:8], 8'b0};
231 16'b???????100000000: begin
233 next_regs = {regs[15:9], 9'b0};
235 16'b??????1000000000: begin
237 next_regs = {regs[15:10], 10'b0};
239 16'b?????10000000000: begin
241 next_regs = {regs[15:11], 11'b0};
243 16'b????100000000000: begin
245 next_regs = {regs[15:12], 12'b0};
247 16'b???1000000000000: begin
249 next_regs = {regs[15:13], 13'b0};
251 16'b??10000000000000: begin
253 next_regs = {regs[15:14], 14'b0};
255 16'b?100000000000000: begin
257 next_regs = {regs[15], 15'b0};
259 16'b1000000000000000: begin
268 cur_reg = insn[23] ? 4'hF - cur_reg : cur_reg;
269 if(cur_reg == 4'hF && insn[22]) begin
279 offset = prev_offset + 6'h4;
280 offset_sel = insn[24] ? offset : prev_offset;
281 raddr = insn[23] ? op0 + {26'b0, offset_sel} : op0 - {26'b0, offset_sel};
283 next_write_reg = 1'b1;
284 next_write_num = cur_reg;
285 next_write_data = rd_data;
291 busaddr = {raddr[31:2], 2'b0};
295 if(next_regs == 16'b0) begin
296 next_lsm_state = 3'b100;
300 next_write_reg = 1'b1;
301 next_write_num = insn[19:16];
302 next_write_data = insn[23] ? op0 + {26'b0, prev_offset} : op0 - {26'b0, prev_offset};
303 next_lsm_state = 3'b001;
308 `DECODE_LDCSTC: if(!inbubble) begin
309 $display("WARNING: Unimplemented LDCSTC");
311 `DECODE_CDP: if(!inbubble) begin
318 /* XXX undefined instruction trap */
319 $display("WARNING: Possible CDP undefined instruction");
322 `DECODE_MRCMCR: if(!inbubble) begin
324 cp_rnw = insn[20] /* L */;
325 if (insn[20] == 0 /* store to coprocessor */)
328 if (insn[15:12] != 4'hF /* Fuck you ARM */) begin
329 next_write_reg = 1'b1;
330 next_write_num = insn[15:12];
331 next_write_data = cp_read;
333 next_outcpsr = {cp_read[31:28], cpsr[27:0]};
340 $display("WARNING: Possible MRCMCR undefined instruction");