1 |
23 |
earlz |
--Memory management component
|
2 |
|
|
--By having this separate, it should be fairly easy to add RAMs or ROMs later
|
3 |
|
|
--This basically lets the CPU not have to worry about how memory "Really" works
|
4 |
|
|
--currently just one RAM. 1024 byte blockram.vhd mapped as 0 - 1023
|
5 |
|
|
|
6 |
|
|
library IEEE;
|
7 |
|
|
use IEEE.STD_LOGIC_1164.ALL;
|
8 |
|
|
use IEEE.NUMERIC_STD.ALL;
|
9 |
|
|
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
entity top is
|
13 |
|
|
port(
|
14 |
|
|
Reset: in std_logic;
|
15 |
|
|
Hold: in std_logic;
|
16 |
|
|
HoldAck: out std_logic;
|
17 |
|
|
Clock: in std_logic;
|
18 |
|
|
DMA: in std_logic; --when high, Address, WriteEnable, and Data are connected to memory
|
19 |
|
|
Address: in std_logic_vector(15 downto 0); --memory address (in bytes)
|
20 |
|
|
WriteEnable: in std_logic;
|
21 |
|
|
Data: inout std_logic_vector(15 downto 0);
|
22 |
|
|
--debug ports
|
23 |
|
|
DebugR0: out std_logic_vector(7 downto 0)
|
24 |
|
|
);
|
25 |
|
|
end top;
|
26 |
|
|
|
27 |
|
|
architecture Behavioral of top is
|
28 |
|
|
|
29 |
|
|
component memory is
|
30 |
|
|
port(
|
31 |
|
|
Address: in std_logic_vector(15 downto 0); --memory address (in bytes)
|
32 |
|
|
WriteWord: in std_logic; --if set, will write a full 16-bit word instead of a byte. Address must be aligned to 16-bit address. (bottom bit must be 0)
|
33 |
|
|
WriteEnable: in std_logic;
|
34 |
|
|
Clock: in std_logic;
|
35 |
|
|
DataIn: in std_logic_vector(15 downto 0);
|
36 |
|
|
DataOut: out std_logic_vector(15 downto 0)
|
37 |
|
|
);
|
38 |
|
|
end component;
|
39 |
|
|
|
40 |
|
|
component core is
|
41 |
|
|
port(
|
42 |
|
|
--memory interface
|
43 |
|
|
MemAddr: out std_logic_vector(15 downto 0); --memory address (in bytes)
|
44 |
|
|
MemWW: out std_logic; --memory writeword
|
45 |
|
|
MemWE: out std_logic; --memory writeenable
|
46 |
|
|
MemIn: in std_logic_vector(15 downto 0);
|
47 |
|
|
MemOut: out std_logic_vector(15 downto 0);
|
48 |
|
|
--general interface
|
49 |
|
|
Clock: in std_logic;
|
50 |
|
|
Reset: in std_logic; --When this is high, CPU will reset within 1 clock cycles.
|
51 |
|
|
--Enable: in std_logic; --When this is high, the CPU executes as normal, when low the CPU stops at the next clock cycle(maintaining all state)
|
52 |
|
|
Hold: in std_logic; --when high, CPU pauses execution and places Memory interfaces into high impendance state so the memory can be used by other components
|
53 |
|
|
HoldAck: out std_logic; --when high, CPU acknowledged hold and buses are in high Z
|
54 |
|
|
--todo: port interface
|
55 |
|
|
|
56 |
|
|
--debug ports:
|
57 |
|
|
DebugIR: out std_logic_vector(15 downto 0); --current instruction
|
58 |
|
|
DebugIP: out std_logic_vector(7 downto 0); --current IP
|
59 |
|
|
DebugCS: out std_logic_vector(7 downto 0); --current code segment
|
60 |
|
|
DebugTR: out std_logic; --current value of TR
|
61 |
|
|
DebugR0: out std_logic_vector(7 downto 0)
|
62 |
|
|
);
|
63 |
|
|
end component;
|
64 |
|
|
signal cpuaddr: std_logic_vector(15 downto 0);
|
65 |
|
|
signal cpuww: std_logic;
|
66 |
|
|
signal cpuwe: std_logic;
|
67 |
|
|
signal cpumemin: std_logic_vector(15 downto 0);
|
68 |
|
|
signal cpumemout: std_logic_vector(15 downto 0);
|
69 |
|
|
signal debugir: std_logic_vector(15 downto 0);
|
70 |
|
|
signal debugip: std_logic_vector(7 downto 0);
|
71 |
|
|
signal debugcs: std_logic_vector(7 downto 0);
|
72 |
|
|
signal debugtr: std_logic;
|
73 |
|
|
|
74 |
|
|
signal MemAddress: std_logic_vector(15 downto 0); --memory address (in bytes)
|
75 |
|
|
signal MemWriteWord: std_logic; --if set, will write a full 16-bit word instead of a byte. Address must be aligned to 16-bit address. (bottom bit must be 0)
|
76 |
|
|
signal MemWriteEnable: std_logic;
|
77 |
|
|
signal MemDataIn: std_logic_vector(15 downto 0);
|
78 |
|
|
signal MemDataOut: std_logic_vector(15 downto 0);
|
79 |
|
|
begin
|
80 |
|
|
cpu: core port map (
|
81 |
|
|
MemAddr => cpuaddr,
|
82 |
|
|
MemWW => cpuww,
|
83 |
|
|
MemWE => cpuwe,
|
84 |
|
|
MemIn => cpumemin,
|
85 |
|
|
MemOut => cpumemout,
|
86 |
|
|
Clock => Clock,
|
87 |
|
|
Reset => Reset,
|
88 |
|
|
Hold => Hold,
|
89 |
|
|
HoldAck => HoldAck,
|
90 |
|
|
DebugIR => DebugIR,
|
91 |
|
|
DebugIP => DebugIP,
|
92 |
|
|
DebugCS => DebugCS,
|
93 |
|
|
DebugTR => DebugTR,
|
94 |
|
|
DebugR0 => DebugR0
|
95 |
|
|
);
|
96 |
|
|
mem: memory port map(
|
97 |
|
|
Address => MemAddress,
|
98 |
|
|
WriteWord => MemWriteWord,
|
99 |
|
|
WriteEnable => MemWriteEnable,
|
100 |
|
|
Clock => Clock,
|
101 |
|
|
DataIn => MemDataIn,
|
102 |
|
|
DataOut => MemDataOut
|
103 |
|
|
);
|
104 |
|
|
|
105 |
|
|
MemAddress <= cpuaddr when DMA='0' else Address;
|
106 |
|
|
MemWriteWord <= cpuww when DMA='0' else '1';
|
107 |
|
|
MemWriteEnable <= cpuwe when DMA='0' else WriteEnable;
|
108 |
|
|
MemDataIn <= cpumemout when DMA='0' else Data when WriteEnable='1' else "ZZZZZZZZZZZZZZZZ";
|
109 |
|
|
cpumemin <= MemDataOut;
|
110 |
|
|
Data <= MemDataOut when DMA='1' and WriteEnable='0' else "ZZZZZZZZZZZZZZZZ";
|
111 |
|
|
|
112 |
|
|
end Behavioral;
|