1 |
2 |
lcdsgmtr |
-- Copyright 2015, Jürgen Defurne
|
2 |
|
|
--
|
3 |
|
|
-- This file is part of the Experimental Unstable CPU System.
|
4 |
|
|
--
|
5 |
|
|
-- The Experimental Unstable CPU System Is free software: you can redistribute
|
6 |
|
|
-- it and/or modify it under the terms of the GNU Lesser General Public License
|
7 |
|
|
-- as published by the Free Software Foundation, either version 3 of the
|
8 |
|
|
-- License, or (at your option) any later version.
|
9 |
|
|
--
|
10 |
|
|
-- The Experimental Unstable CPU System is distributed in the hope that it will
|
11 |
|
|
-- be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
|
13 |
|
|
-- General Public License for more details.
|
14 |
|
|
--
|
15 |
|
|
-- You should have received a copy of the GNU Lesser General Public License
|
16 |
|
|
-- along with Experimental Unstable CPU System. If not, see
|
17 |
|
|
-- http://www.gnu.org/licenses/lgpl.txt.
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
LIBRARY ieee;
|
21 |
|
|
USE ieee.std_logic_1164.ALL;
|
22 |
|
|
USE ieee.numeric_std.ALL;
|
23 |
|
|
|
24 |
|
|
ENTITY bigrf IS
|
25 |
|
|
|
26 |
|
|
GENERIC (
|
27 |
|
|
bus_width : NATURAL := 16);
|
28 |
|
|
|
29 |
|
|
PORT (
|
30 |
|
|
clock : IN STD_LOGIC;
|
31 |
|
|
port_a_in : IN STD_LOGIC_VECTOR(bus_width - 1 DOWNTO 0);
|
32 |
|
|
port_a_addr : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
|
33 |
|
|
port_a_wr : IN STD_LOGIC;
|
34 |
|
|
port_b_in : IN STD_LOGIC_VECTOR(bus_width - 1 DOWNTO 0);
|
35 |
|
|
port_b_addr : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
|
36 |
|
|
port_b_wr : IN STD_LOGIC;
|
37 |
|
|
port_c_out : OUT STD_LOGIC_VECTOR(bus_width - 1 DOWNTO 0);
|
38 |
|
|
port_c_addr : IN STD_LOGIC_VECTOR(3 DOWNTO 0);
|
39 |
|
|
port_d_out : OUT STD_LOGIC_VECTOR(bus_width - 1 DOWNTO 0);
|
40 |
|
|
port_d_addr : IN STD_LOGIC_VECTOR(3 DOWNTO 0));
|
41 |
|
|
|
42 |
|
|
END bigrf;
|
43 |
|
|
|
44 |
|
|
ARCHITECTURE Behavioral OF bigrf IS
|
45 |
|
|
|
46 |
|
|
TYPE reg_t IS ARRAY (0 TO 15) OF STD_LOGIC_VECTOR(bus_width - 1 DOWNTO 0);
|
47 |
|
|
|
48 |
|
|
SIGNAL reg_l : reg_t;
|
49 |
|
|
SIGNAL reg_r : reg_t;
|
50 |
|
|
|
51 |
|
|
BEGIN -- Behavioral
|
52 |
|
|
|
53 |
|
|
-- purpose: Four-port register file
|
54 |
|
|
-- type : sequential
|
55 |
|
|
-- inputs : clock, port_n_in, port_n_addr, port_n_wr
|
56 |
|
|
-- outputs: port_c_out,port_d_out
|
57 |
|
|
RF1 : PROCESS (clock)
|
58 |
|
|
BEGIN -- PROCESS RF1
|
59 |
|
|
IF rising_edge(clock) THEN -- rising clock edge
|
60 |
|
|
-- Outputs
|
61 |
|
|
port_c_out <= reg_l(to_integer(UNSIGNED(port_c_addr)));
|
62 |
|
|
port_d_out <= reg_r(to_integer(UNSIGNED(port_d_addr)));
|
63 |
|
|
|
64 |
|
|
-- Inputs
|
65 |
|
|
-- If port A and port B have the same address, then there has to be a
|
66 |
|
|
-- choice to which port has preference
|
67 |
|
|
IF port_a_wr = '1' AND port_b_wr = '0' THEN
|
68 |
|
|
reg_r(to_integer(UNSIGNED(port_a_addr))) <= port_a_in;
|
69 |
|
|
reg_l(to_integer(UNSIGNED(port_a_addr))) <= port_a_in;
|
70 |
|
|
|
71 |
|
|
reg_r(to_integer(UNSIGNED(port_b_addr))) <= reg_r(to_integer(UNSIGNED(port_b_addr)));
|
72 |
|
|
reg_l(to_integer(UNSIGNED(port_b_addr))) <= reg_l(to_integer(UNSIGNED(port_b_addr)));
|
73 |
|
|
ELSIF port_a_wr = '0' AND port_b_wr = '1' THEN
|
74 |
|
|
reg_r(to_integer(UNSIGNED(port_a_addr))) <= reg_r(to_integer(UNSIGNED(port_a_addr)));
|
75 |
|
|
reg_l(to_integer(UNSIGNED(port_a_addr))) <= reg_l(to_integer(UNSIGNED(port_a_addr)));
|
76 |
|
|
|
77 |
|
|
reg_r(to_integer(UNSIGNED(port_b_addr))) <= port_b_in;
|
78 |
|
|
reg_l(to_integer(UNSIGNED(port_b_addr))) <= port_b_in;
|
79 |
|
|
ELSIF port_a_wr = '1' AND port_b_wr = '1' THEN
|
80 |
|
|
IF port_a_addr = port_b_addr THEN
|
81 |
|
|
reg_r(to_integer(UNSIGNED(port_a_addr))) <= port_b_in;
|
82 |
|
|
reg_l(to_integer(UNSIGNED(port_a_addr))) <= port_b_in;
|
83 |
|
|
reg_r(to_integer(UNSIGNED(port_b_addr))) <= port_b_in;
|
84 |
|
|
reg_l(to_integer(UNSIGNED(port_b_addr))) <= port_b_in;
|
85 |
|
|
ELSE
|
86 |
|
|
reg(to_integer(UNSIGNED(port_a_addr))) <= port_a_in;
|
87 |
|
|
reg(to_integer(UNSIGNED(port_b_addr))) <= port_b_in;
|
88 |
|
|
END IF;
|
89 |
|
|
ELSE
|
90 |
|
|
reg(to_integer(UNSIGNED(port_a_addr))) <= reg(to_integer(UNSIGNED(port_a_addr)));
|
91 |
|
|
reg(to_integer(UNSIGNED(port_b_addr))) <= reg(to_integer(UNSIGNED(port_b_addr)));
|
92 |
|
|
END IF;
|
93 |
|
|
END IF;
|
94 |
|
|
END PROCESS RF1;
|
95 |
|
|
|
96 |
|
|
END Behavioral;
|