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,
29 input [3:0] write_num,
30 input [31:0] write_data,
35 output reg [31:0] outpc,
36 output reg [31:0] outinsn,
37 output reg out_write_reg = 1'b0,
38 output reg [3:0] out_write_num = 4'bxxxx,
39 output reg [31:0] out_write_data = 32'hxxxxxxxx,
40 output reg [31:0] out_spsr = 32'hxxxxxxxx,
41 output reg [31:0] out_cpsr = 32'hxxxxxxxx
44 reg [31:0] addr, raddr, prev_raddr, next_regdata, next_outcpsr;
45 reg [3:0] next_regsel, cur_reg, prev_reg;
46 reg next_writeback, next_notdone, next_inc_next;
47 reg [31:0] align_s1, align_s2, align_rddata;
51 wire [3:0] next_write_num;
52 wire [31:0] next_write_data;
54 reg [15:0] regs, next_regs;
55 reg started = 1'b0, next_started;
56 reg [5:0] offset, prev_offset, offset_sel;
65 outbubble <= next_outbubble;
66 out_write_reg <= next_write_reg;
67 out_write_num <= next_write_num;
68 out_write_data <= next_write_data;
69 notdone <= next_notdone;
70 inc_next <= next_inc_next;
73 started <= next_started;
74 prev_offset <= offset;
76 out_cpsr <= next_outcpsr;
86 wr_data = 32'hxxxxxxxx;
87 busaddr = 32'hxxxxxxxx;
90 next_write_reg = write_reg;
91 next_write_num = write_num;
92 next_write_data = write_data;
94 next_outbubble = inbubble;
97 next_started = started;
99 next_outcpsr = started ? out_cpsr : cpsr;
102 `DECODE_LDRSTR_UNDEFINED: begin end
103 `DECODE_LDRSTR: begin
105 next_outbubble = rw_wait;
106 outstall = rw_wait | notdone;
108 addr = insn[23] ? op0 + op1 : op0 - op1; /* up/down select */
109 raddr = insn[24] ? op0 : addr; /* pre/post increment */
110 busaddr = {raddr[31:2], 2'b0};
114 /* rotate to correct position */
115 align_s1 = raddr[1] ? {rd_data[15:0], rd_data[31:16]} : rd_data;
116 align_s2 = raddr[0] ? {align_s1[7:0], align_s1[31:8]} : align_s1;
117 /* select byte or word */
118 align_rddata = insn[22] ? {24'b0, align_s2[7:0]} : align_s2;
121 wr_data = insn[22] ? {4{op2[7:0]}} : op2; /* XXX need to actually store just a byte */
123 else if(!inc_next) begin
124 next_write_reg = 1'b1;
125 next_write_num = insn[15:12];
126 next_write_data = align_rddata;
127 next_inc_next = 1'b1;
129 else if(insn[21]) begin
130 next_write_reg = 1'b1;
131 next_write_num = insn[19:16];
132 next_write_data = addr;
134 next_notdone = rw_wait & insn[20] & insn[21];
137 `DECODE_LDMSTM: begin
141 // next_regs = insn[23] ? op1[15:0] : op1[0:15];
142 /** verilator can suck my dick */
143 next_regs = insn[23] ? op1[15:0] : {op1[0], op1[1], op1[2], op1[3], op1[4], op1[5], op1[6], op1[7],
144 op1[8], op1[9], op1[10], op1[11], op1[12], op1[13], op1[14], op1[15]};
148 else if(inc_next) begin
150 next_write_reg = 1'b1;
151 next_write_num = insn[19:16];
152 next_write_data = insn[23] ? op0 + {26'b0, prev_offset} : op0 - {26'b0, prev_offset};
156 else if(rw_wait) begin
163 16'b???????????????1: begin
165 next_regs = {regs[15:1], 1'b0};
167 16'b??????????????10: begin
169 next_regs = {regs[15:2], 2'b0};
171 16'b?????????????100: begin
173 next_regs = {regs[15:3], 3'b0};
175 16'b????????????1000: begin
177 next_regs = {regs[15:4], 4'b0};
179 16'b???????????10000: begin
181 next_regs = {regs[15:5], 5'b0};
183 16'b??????????100000: begin
185 next_regs = {regs[15:6], 6'b0};
187 16'b?????????1000000: begin
189 next_regs = {regs[15:7], 7'b0};
191 16'b????????10000000: begin
193 next_regs = {regs[15:8], 8'b0};
195 16'b???????100000000: begin
197 next_regs = {regs[15:9], 9'b0};
199 16'b??????1000000000: begin
201 next_regs = {regs[15:10], 10'b0};
203 16'b?????10000000000: begin
205 next_regs = {regs[15:11], 11'b0};
207 16'b????100000000000: begin
209 next_regs = {regs[15:12], 12'b0};
211 16'b???1000000000000: begin
213 next_regs = {regs[15:13], 13'b0};
215 16'b??10000000000000: begin
217 next_regs = {regs[15:14], 14'b0};
219 16'b?100000000000000: begin
221 next_regs = {regs[15], 15'b0};
223 16'b1000000000000000: begin
232 cur_reg = insn[23] ? 4'hF - cur_reg : cur_reg;
233 if(cur_reg == 4'hF && insn[22]) begin
236 offset = prev_offset + 6'h4;
237 offset_sel = insn[24] ? offset : prev_offset;
238 raddr = insn[23] ? op0 + {26'b0, offset_sel} : op0 - {26'b0, offset_sel};
241 next_write_reg = 1'b1;
242 next_write_num = cur_reg;
243 next_write_data = rd_data;
249 next_inc_next = next_regs == 16'b0;
250 next_notdone = ~next_inc_next | rw_wait;
251 busaddr = {raddr[31:2], 2'b0};