OpenCores
URL https://opencores.org/ocsvn/lxp32/lxp32/trunk

Subversion Repositories lxp32

[/] [lxp32/] [trunk/] [rtl/] [lxp32_execute.vhd] - Blame information for rev 8

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ring0_mipt
---------------------------------------------------------------------
2
-- Execution unit
3
--
4
-- Part of the LXP32 CPU
5
--
6
-- Copyright (c) 2016 by Alex I. Kuznetsov
7
--
8
-- The third stage of the LXP32 pipeline.
9
---------------------------------------------------------------------
10
 
11
library ieee;
12
use ieee.std_logic_1164.all;
13
 
14
entity lxp32_execute is
15
        generic(
16
                DBUS_RMW: boolean;
17
                DIVIDER_EN: boolean;
18
                MUL_ARCH: string
19
        );
20
        port(
21
                clk_i: in std_logic;
22
                rst_i: in std_logic;
23
 
24
                cmd_loadop3_i: in std_logic;
25
                cmd_signed_i: in std_logic;
26
                cmd_dbus_i: in std_logic;
27
                cmd_dbus_store_i: in std_logic;
28
                cmd_dbus_byte_i: in std_logic;
29
                cmd_addsub_i: in std_logic;
30
                cmd_mul_i: in std_logic;
31
                cmd_div_i: in std_logic;
32
                cmd_div_mod_i: in std_logic;
33
                cmd_cmp_i: in std_logic;
34
                cmd_jump_i: in std_logic;
35
                cmd_negate_op2_i: in std_logic;
36
                cmd_and_i: in std_logic;
37
                cmd_xor_i: in std_logic;
38
                cmd_shift_i: in std_logic;
39
                cmd_shift_right_i: in std_logic;
40
 
41
                jump_type_i: in std_logic_vector(3 downto 0);
42
 
43
                op1_i: in std_logic_vector(31 downto 0);
44
                op2_i: in std_logic_vector(31 downto 0);
45
                op3_i: in std_logic_vector(31 downto 0);
46
                dst_i: in std_logic_vector(7 downto 0);
47
 
48
                sp_waddr_o: out std_logic_vector(7 downto 0);
49
                sp_we_o: out std_logic;
50
                sp_wdata_o: out std_logic_vector(31 downto 0);
51
 
52
                valid_i: in std_logic;
53
                ready_o: out std_logic;
54
 
55
                dbus_cyc_o: out std_logic;
56
                dbus_stb_o: out std_logic;
57
                dbus_we_o: out std_logic;
58
                dbus_sel_o: out std_logic_vector(3 downto 0);
59
                dbus_ack_i: in std_logic;
60
                dbus_adr_o: out std_logic_vector(31 downto 2);
61
                dbus_dat_o: out std_logic_vector(31 downto 0);
62
                dbus_dat_i: in std_logic_vector(31 downto 0);
63
 
64
                jump_valid_o: out std_logic;
65
                jump_dst_o: out std_logic_vector(29 downto 0);
66
                jump_ready_i: in std_logic;
67
 
68 6 ring0_mipt
                interrupt_return_o: out std_logic
69 2 ring0_mipt
        );
70
end entity;
71
 
72
architecture rtl of lxp32_execute is
73
 
74
-- Pipeline control signals
75
 
76
signal busy: std_logic;
77
signal can_execute: std_logic;
78
 
79
-- ALU signals
80
 
81
signal alu_result: std_logic_vector(31 downto 0);
82
signal alu_we: std_logic;
83
signal alu_busy: std_logic;
84
 
85
signal alu_cmp_eq: std_logic;
86
signal alu_cmp_ug: std_logic;
87
signal alu_cmp_sg: std_logic;
88
 
89
-- OP3 loader signals
90
 
91
signal loadop3_we: std_logic;
92
 
93
-- Jump machine signals
94
 
95
signal jump_condition: std_logic;
96
signal jump_valid: std_logic:='0';
97
signal jump_dst: std_logic_vector(jump_dst_o'range);
98
 
99
-- DBUS signals
100
 
101
signal dbus_result: std_logic_vector(31 downto 0);
102
signal dbus_busy: std_logic;
103
signal dbus_we: std_logic;
104
 
105
-- Result mux signals
106
 
107
signal result_mux: std_logic_vector(31 downto 0);
108
signal result_valid: std_logic;
109
signal result_regaddr: std_logic_vector(7 downto 0);
110
 
111
signal dst_reg: std_logic_vector(7 downto 0);
112
 
113
-- Signals related to interrupt handling
114
 
115
signal interrupt_return: std_logic:='0';
116
 
117
begin
118
 
119
-- Pipeline control
120
 
121
busy<=alu_busy or dbus_busy;
122
ready_o<=not busy;
123
can_execute<=valid_i and not busy;
124
 
125
-- ALU
126
 
127
alu_inst: entity work.lxp32_alu(rtl)
128
        generic map(
129
                DIVIDER_EN=>DIVIDER_EN,
130
                MUL_ARCH=>MUL_ARCH
131
        )
132
        port map(
133
                clk_i=>clk_i,
134
                rst_i=>rst_i,
135
 
136
                valid_i=>can_execute,
137
 
138
                cmd_signed_i=>cmd_signed_i,
139
                cmd_addsub_i=>cmd_addsub_i,
140
                cmd_mul_i=>cmd_mul_i,
141
                cmd_div_i=>cmd_div_i,
142
                cmd_div_mod_i=>cmd_div_mod_i,
143
                cmd_cmp_i=>cmd_cmp_i,
144
                cmd_negate_op2_i=>cmd_negate_op2_i,
145
                cmd_and_i=>cmd_and_i,
146
                cmd_xor_i=>cmd_xor_i,
147
                cmd_shift_i=>cmd_shift_i,
148
                cmd_shift_right_i=>cmd_shift_right_i,
149
 
150
                op1_i=>op1_i,
151
                op2_i=>op2_i,
152
 
153
                result_o=>alu_result,
154
 
155
                cmp_eq_o=>alu_cmp_eq,
156
                cmp_ug_o=>alu_cmp_ug,
157
                cmp_sg_o=>alu_cmp_sg,
158
 
159
                we_o=>alu_we,
160
                busy_o=>alu_busy
161
        );
162
 
163
-- OP3 loader
164
 
165
loadop3_we<=can_execute and cmd_loadop3_i;
166
 
167
-- Jump logic
168
 
169
jump_condition<=(not cmd_cmp_i) or (jump_type_i(3) and alu_cmp_eq) or
170
        (jump_type_i(2) and not alu_cmp_eq) or (jump_type_i(1) and alu_cmp_ug) or
171
        (jump_type_i(0) and alu_cmp_sg);
172
 
173
process (clk_i) is
174
begin
175
        if rising_edge(clk_i) then
176
                if rst_i='1' then
177
                        jump_valid<='0';
178
                        interrupt_return<='0';
179 6 ring0_mipt
                        jump_dst<=(others=>'-');
180 2 ring0_mipt
                else
181
                        if jump_valid='0' then
182 6 ring0_mipt
                                jump_dst<=op1_i(31 downto 2);
183 2 ring0_mipt
                                if can_execute='1' and cmd_jump_i='1' and jump_condition='1' then
184
                                        jump_valid<='1';
185
                                        interrupt_return<=op1_i(0);
186
                                end if;
187
                        elsif jump_ready_i='1' then
188
                                jump_valid<='0';
189
                                interrupt_return<='0';
190
                        end if;
191
                end if;
192
        end if;
193
end process;
194
 
195
jump_valid_o<=jump_valid or (can_execute and cmd_jump_i and jump_condition);
196
jump_dst_o<=jump_dst when jump_valid='1' else op1_i(31 downto 2);
197
 
198
interrupt_return_o<=interrupt_return;
199
 
200
-- DBUS access
201
 
202
dbus_inst: entity work.lxp32_dbus(rtl)
203
        generic map(
204
                RMW=>DBUS_RMW
205
        )
206
        port map(
207
                clk_i=>clk_i,
208
                rst_i=>rst_i,
209
 
210
                valid_i=>can_execute,
211
 
212
                cmd_dbus_i=>cmd_dbus_i,
213
                cmd_dbus_store_i=>cmd_dbus_store_i,
214
                cmd_dbus_byte_i=>cmd_dbus_byte_i,
215
                cmd_signed_i=>cmd_signed_i,
216
                addr_i=>op1_i,
217
                wdata_i=>op2_i,
218
 
219
                rdata_o=>dbus_result,
220
                busy_o=>dbus_busy,
221
                we_o=>dbus_we,
222
 
223
                dbus_cyc_o=>dbus_cyc_o,
224
                dbus_stb_o=>dbus_stb_o,
225
                dbus_we_o=>dbus_we_o,
226
                dbus_sel_o=>dbus_sel_o,
227
                dbus_ack_i=>dbus_ack_i,
228
                dbus_adr_o=>dbus_adr_o,
229
                dbus_dat_o=>dbus_dat_o,
230
                dbus_dat_i=>dbus_dat_i
231
        );
232
 
233
-- Result multiplexer
234
 
235
result_mux_gen: for i in result_mux'range generate
236
        result_mux(i)<=(alu_result(i) and alu_we) or
237
                (op3_i(i) and loadop3_we) or
238
                (dbus_result(i) and dbus_we);
239
end generate;
240
 
241
result_valid<=alu_we or loadop3_we or dbus_we;
242
 
243
-- Write destination register
244
 
245
process (clk_i) is
246
begin
247
        if rising_edge(clk_i) then
248
                if can_execute='1' then
249
                        dst_reg<=dst_i;
250
                end if;
251
        end if;
252
end process;
253
 
254
result_regaddr<=dst_i when can_execute='1' else dst_reg;
255
 
256
sp_we_o<=result_valid;
257
sp_waddr_o<=result_regaddr;
258
sp_wdata_o<=result_mux;
259
 
260
end architecture;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.