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

Subversion Repositories arm4u

[/] [arm4u/] [trunk/] [hdl/] [writeback.vhd] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Bregalad
-- This file is part of ARM4U CPU
2
-- 
3
-- This is a creation of the Laboratory of Processor Architecture
4
-- of Ecole Polytechnique Fédérale de Lausanne ( http://lap.epfl.ch )
5
--
6
-- writeback.vhd  --  Description of the writeback pipeline stage
7
--
8
-- Written By -  Jonathan Masur and Xavier Jimenez (2013)
9
--
10
-- This program is free software; you can redistribute it and/or modify it
11
-- under the terms of the GNU General Public License as published by the
12
-- Free Software Foundation; either version 2, or (at your option) any
13
-- later version.
14
--
15
-- This program is distributed in the hope that it will be useful,
16
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
17
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
-- GNU General Public License for more details.
19
--
20
-- In other words, you are welcome to use, share and improve this program.
21
-- You are forbidden to forbid anyone else to use, share and improve
22
-- what you give them.   Help stamp out software-hoarding!
23
 
24
library ieee;
25
use ieee.std_logic_1164.all;
26
use ieee.numeric_std.all;
27
use work.arm_types.all;
28
 
29
entity writeback is
30
        port(
31
                clk : in std_logic;
32
 
33
                wb_stage_valid : in std_logic;
34
                wb_rdest_wren : in std_logic;
35
                wb_rdest_adr : in std_logic_vector(4 downto 0);
36
                wb_branch_en : in std_logic;
37
                wb_wb_sel : in std_logic;
38
                wb_exe_data : in std_logic_vector(31 downto 0);
39
                wb_mem_ctrl : in MEM_OPERATION;
40
 
41
                rfile_wr_enable : out std_logic;
42
                rfile_address : out std_logic_vector(4 downto 0);
43
                wb_data : out std_logic_vector(31 downto 0);
44
 
45
                fwd_wb2_enable : out std_logic;
46
                fwd_wb2_address : out std_logic_vector(4 downto 0);
47
                fwd_wb2_data : out std_logic_vector(31 downto 0);
48
 
49
                avm_data_readdatavalid : in  std_logic;
50
                avm_data_readdata      : in  std_logic_vector(31 downto 0);
51
 
52
                wb_pc_wr : out std_logic;
53
                wb_blocked_n : out std_logic
54
        );
55
end entity;
56
 
57
architecture rtl of writeback is
58
        signal outdata : std_logic_vector(31 downto 0);
59
        signal avalon_data : std_logic_vector(31 downto 0);
60
        signal rd_ok : std_logic;
61
 
62
begin
63
        -- 0 if the stage should stall because read data is not valid
64
        rd_ok <= avm_data_readdatavalid when wb_mem_ctrl = LOAD_WORD or wb_mem_ctrl = LOAD_BYTE or wb_mem_ctrl = LOAD_BURST else '1';
65
        wb_blocked_n <= rd_ok or not wb_stage_valid;
66
 
67
        -- write to PC on branches from avalon data
68
        wb_pc_wr <= wb_branch_en and wb_wb_sel and wb_stage_valid and rd_ok;
69
 
70
        -- output MUX between avalon data and execute data
71
        outdata <= wb_exe_data when wb_wb_sel = '0' else avalon_data;
72
 
73
        -- register file signals (also writeback 1 forwarding path)
74
        rfile_wr_enable <= wb_rdest_wren and wb_stage_valid;
75
        rfile_address <= wb_rdest_adr;
76
        wb_data <= outdata;
77
 
78
        avm : process(wb_exe_data, avm_data_readdata, wb_mem_ctrl) is
79
        begin
80
                -- convert byte->word if a load byte command
81
                if wb_mem_ctrl = LOAD_BYTE
82
                then
83
                        case wb_exe_data(1 downto 0) is
84
                        when "00" =>
85
                                avalon_data <= (31 downto 8 => '0') & avm_data_readdata(7 downto 0);
86
                        when "01" =>
87
                                avalon_data <= (31 downto 8 => '0') & avm_data_readdata(15 downto 8);
88
                        when "10" =>
89
                                avalon_data <= (31 downto 8 => '0') & avm_data_readdata(23 downto 16);
90
                        when others =>
91
                                avalon_data <= (31 downto 8 => '0') & avm_data_readdata(31 downto 24);
92
                        end case;
93
                else
94
                -- else data just goes through
95
                        avalon_data <= avm_data_readdata;
96
                end if;
97
        end process;
98
 
99
        -- register for writeback2 forwarding path
100
        process(clk) is
101
        begin
102
                if rising_edge(clk)
103
                then
104
                        fwd_wb2_enable <= wb_rdest_wren and wb_stage_valid;
105
                        fwd_wb2_address <= wb_rdest_adr;
106
                        fwd_wb2_data <= outdata;
107
                end if;
108
        end process;
109
 
110
end architecture;

powered by: WebSVN 2.1.0

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