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 */
34 input [3:0] write_num,
35 input [31:0] write_data,
40 output reg [31:0] outpc,
41 output reg [31:0] outinsn,
42 output reg out_write_reg = 1'b0,
43 output reg [3:0] out_write_num = 4'bxxxx,
44 output reg [31:0] out_write_data = 32'hxxxxxxxx,
45 output reg [31:0] out_spsr = 32'hxxxxxxxx,
46 output reg [31:0] out_cpsr = 32'hxxxxxxxx
49 reg [31:0] addr, raddr, prev_raddr, next_regdata, next_outcpsr;
50 reg [3:0] next_regsel, cur_reg, prev_reg;
51 reg next_writeback, next_notdone, next_inc_next;
52 reg [31:0] align_s1, align_s2, align_rddata;
56 wire [3:0] next_write_num;
57 wire [31:0] next_write_data;
59 reg [15:0] regs, next_regs;
60 reg started = 1'b0, next_started;
61 reg [5:0] offset, prev_offset, offset_sel;
70 outbubble <= next_outbubble;
71 out_write_reg <= next_write_reg;
72 out_write_num <= next_write_num;
73 out_write_data <= next_write_data;
74 notdone <= next_notdone;
75 inc_next <= next_inc_next;
78 started <= next_started;
79 prev_offset <= offset;
81 out_cpsr <= next_outcpsr;
91 wr_data = 32'hxxxxxxxx;
92 busaddr = 32'hxxxxxxxx;
95 next_write_reg = write_reg;
96 next_write_num = write_num;
97 next_write_data = write_data;
99 next_outbubble = inbubble;
102 next_started = started;
104 offset = prev_offset;
105 next_outcpsr = started ? out_cpsr : cpsr;
108 `DECODE_LDRSTR_UNDEFINED: begin end
109 `DECODE_LDRSTR: begin
111 next_outbubble = rw_wait;
112 outstall = rw_wait | notdone;
114 addr = insn[23] ? op0 + op1 : op0 - op1; /* up/down select */
115 raddr = insn[24] ? op0 : addr; /* pre/post increment */
116 busaddr = {raddr[31:2], 2'b0};
120 /* rotate to correct position */
121 align_s1 = raddr[1] ? {rd_data[15:0], rd_data[31:16]} : rd_data;
122 align_s2 = raddr[0] ? {align_s1[7:0], align_s1[31:8]} : align_s1;
123 /* select byte or word */
124 align_rddata = insn[22] ? {24'b0, align_s2[7:0]} : align_s2;
127 wr_data = insn[22] ? {4{op2[7:0]}} : op2; /* XXX need to actually store just a byte */
129 else if(!inc_next) begin
130 next_write_reg = 1'b1;
131 next_write_num = insn[15:12];
132 next_write_data = align_rddata;
133 next_inc_next = 1'b1;
135 else if(insn[21]) begin
136 next_write_reg = 1'b1;
137 next_write_num = insn[19:16];
138 next_write_data = addr;
140 next_notdone = rw_wait & insn[20] & insn[21];
143 `DECODE_LDMSTM: begin
147 // next_regs = insn[23] ? op1[15:0] : op1[0:15];
148 /** verilator can suck my dick */
149 next_regs = insn[23] ? op1[15:0] : {op1[0], op1[1], op1[2], op1[3], op1[4], op1[5], op1[6], op1[7],
150 op1[8], op1[9], op1[10], op1[11], op1[12], op1[13], op1[14], op1[15]};
154 else if(inc_next) begin
156 next_write_reg = 1'b1;
157 next_write_num = insn[19:16];
158 next_write_data = insn[23] ? op0 + {26'b0, prev_offset} : op0 - {26'b0, prev_offset};
162 else if(rw_wait) begin
169 16'b???????????????1: begin
171 next_regs = {regs[15:1], 1'b0};
173 16'b??????????????10: begin
175 next_regs = {regs[15:2], 2'b0};
177 16'b?????????????100: begin
179 next_regs = {regs[15:3], 3'b0};
181 16'b????????????1000: begin
183 next_regs = {regs[15:4], 4'b0};
185 16'b???????????10000: begin
187 next_regs = {regs[15:5], 5'b0};
189 16'b??????????100000: begin
191 next_regs = {regs[15:6], 6'b0};
193 16'b?????????1000000: begin
195 next_regs = {regs[15:7], 7'b0};
197 16'b????????10000000: begin
199 next_regs = {regs[15:8], 8'b0};
201 16'b???????100000000: begin
203 next_regs = {regs[15:9], 9'b0};
205 16'b??????1000000000: begin
207 next_regs = {regs[15:10], 10'b0};
209 16'b?????10000000000: begin
211 next_regs = {regs[15:11], 11'b0};
213 16'b????100000000000: begin
215 next_regs = {regs[15:12], 12'b0};
217 16'b???1000000000000: begin
219 next_regs = {regs[15:13], 13'b0};
221 16'b??10000000000000: begin
223 next_regs = {regs[15:14], 14'b0};
225 16'b?100000000000000: begin
227 next_regs = {regs[15], 15'b0};
229 16'b1000000000000000: begin
238 cur_reg = insn[23] ? 4'hF - cur_reg : cur_reg;
239 if(cur_reg == 4'hF && insn[22]) begin
242 offset = prev_offset + 6'h4;
243 offset_sel = insn[24] ? offset : prev_offset;
244 raddr = insn[23] ? op0 + {26'b0, offset_sel} : op0 - {26'b0, offset_sel};
247 next_write_reg = 1'b1;
248 next_write_num = cur_reg;
249 next_write_data = rd_data;
255 next_inc_next = next_regs == 16'b0;
256 next_notdone = ~next_inc_next | rw_wait;
257 busaddr = {raddr[31:2], 2'b0};