-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharm_core.v
193 lines (175 loc) · 4.87 KB
/
arm_core.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
* Top-level module for instantiating all other modules.
*/
module arm_core
(
// Inputs
input clk, rst,
input [31:0] inst, // Instruction from memory
input [31:0] mem_data_out, // Data from memory load
// Outputs
output reg halted,
output reg [31:0] mem_addr, // Address of data to load/store
output reg [31:0] inst_addr, // Address of next instruction to load from memory
output reg [31:0] mem_data_in, // Data for memory store
output reg mem_write_en // Enable writes to memory for store ops
);
always @(posedge clk) begin
if (!rst) begin
$display("instruction: %x", inst);
$display("rn_out: %x, shifter_op: %x alu_out: %x", rn_out, shifter_operand, alu_out);
inst_addr <= pc_out;
if (inst == 32'hef00000a)
halted <= 1'b1;
end
end
initial begin
$monitor("\ninst: %x | %b\nalu_sel: %x, barrel_sel: %x, shiftee_sel: %x, shifter_sel: %x\nread_rn: %x, write_rd: %x, read_rm: %x, read_rs: %x\n-------\n",
inst, inst, alu_sel, barrel_sel, shiftee_sel, shifter_sel, read_rn, write_rd, read_rm, read_rs);
end
/*initial begin
$monitor("inst: %x | %b\nshiftee_sel: %b, shifter_sel: %b\nimmed_32: %d shift_imm: %b\nread_rn: %d, pc_we: %d\n---------\n",
inst, inst, shiftee_sel, shifter_sel, immed_32, shift_imm, read_rn, pc_we);
end
*/
// For register_file:
wire rd_we;
wire [31:0] rd_in;
wire [3:0] write_rd;
wire [3:0] read_rn, read_rm, read_rs;
wire [31:0] pc_in, cpsr_in;
wire pc_we, cpsr_we;
wire [31:0] rn_out, rm_out, rs_out;
wire [31:0] pc_out, cpsr_out;
// For cond_decode:
wire cond_pass;
// For shiftee_mux:
wire [1:0] shiftee_sel;
wire [7:0] immed_8;
wire [31:0] immed_32;
wire [31:0] shiftee;
// For shifter_mux:
wire [1:0] shifter_sel;
wire [3:0] rotate_imm;
wire [4:0] shift_imm;
wire [31:0] shifter;
// For barrel_shifter:
wire [3:0] barrel_sel;
wire [31:0] shifter_operand;
wire [31:0] shifter_carry_out;
// For arm_alu:
wire [31:0] alu_out;
wire [3:0] alu_sel;
register_file Register
(
// Inputs
.clk(clk),
.reset(rst),
.rd_we(rd_we),
.rd_in(rd_in),
.write_rd(write_rd),
.read_rn(read_rn),
.read_rm(read_rm),
.read_rs(read_rs),
.pc_in(pc_in),
.cpsr_in(cpsr_in),
.pc_we(pc_we),
// Outputs
.rn_out(rn_out),
.rm_out(rm_out),
.rs_out(rs_out),
.pc_out(pc_out),
.cpsr_out(cpsr_out)
);
cond_decode CondDecoder
(
// Inputs
.inst(inst),
.cpsr(cpsr_out),
// Outputs
.valid(cond_pass)
);
shiftee_mux ShifteeMux
(
// Inputs
.sel(shiftee_sel),
.immed_8(immed_8),
.immed_32(immed_32),
.rm(rm_out),
// Output
.shiftee(shiftee)
);
shifter_mux ShifterMux
(
// Inputs
.sel(shifter_sel),
.rotate_imm(rotate_imm),
.shift_imm(shift_imm),
.rs(rs_out),
// Output
.shifter(shifter)
);
barrel_shifter Shifter
(
// Inputs
.c_flag(cpsr_out[`CPSR_C]),
.barrel_sel(barrel_sel),
.shiftee(shiftee),
.shifter(shifter),
// Outputs
.shifter_operand(shifter_operand),
.shifter_carry_out(shifter_carry_out)
);
arm_alu alu
(
// Outputs
.alu_out(alu_out),
.cpsr_next(cpsr_in),
// Inputs
.alu_op1(rn_out),
.alu_op2(shifter_operand),
.alu_op_sel(alu_sel),
.cpsr_prev(cpsr_out)
);
arm_decode ControlDecodeUnit
(
// Inputs
.cond_pass(cond_pass),
.inst(inst),
.rn_out(rn_out),
.rm_out(rm_out),
.rs_out(rs_out),
.pc_out(pc_out),
.cpsr_out(cpsr_out),
.alu_out(alu_out),
// Outputs
// To register_file:
.write_rd(write_rd),
.read_rn(read_rn),
.read_rm(read_rm),
.read_rs(read_rs),
.rd_we(rd_we),
.pc_we(pc_we),
.cpsr_we(cpsr_we),
.rd_in(rd_in),
.pc_in(pc_in),
// To shiftee_mux:
.shiftee_sel(shiftee_sel),
.immed_8_shiftee_in(immed_8),
.immed_32_shiftee_in(immed_32),
// To shifter_mux:
.shifter_sel(shifter_sel),
.rotate_imm_shifter_in(rotate_imm),
.shift_imm_shifter_in(shift_imm),
// To arm_alu:
.alu_sel(alu_sel),
// To barrel_shifter:
.barrel_sel(barrel_sel)
);
//arm_mac mac
//(
//);
// Instantiate muxes as required between each module
// Mux select lines will have to be appropriately set
// by the main decode unit
endmodule