| 1 |
2 |
idiolatrie |
--------------------------------------------------------------------------------
|
| 2 |
|
|
-- MIPS™ I CPU - Wishbone Master --
|
| 3 |
|
|
--------------------------------------------------------------------------------
|
| 4 |
|
|
-- --
|
| 5 |
|
|
-- KNOWN BUGS: --
|
| 6 |
|
|
-- --
|
| 7 |
|
|
-- o The master cause some severe trouble when communicating with slave --
|
| 8 |
|
|
-- interfaces that run on a different frequency than the master itself. --
|
| 9 |
|
|
-- In order to get the DDR to work with a 50 MHz master, I added an --
|
| 10 |
|
|
-- interface solely running at 50 MHz while the remaining DDR controller --
|
| 11 |
|
|
-- runs at 25 MHz. --
|
| 12 |
|
|
-- --
|
| 13 |
|
|
--------------------------------------------------------------------------------
|
| 14 |
|
|
-- Copyright (C)2011 Mathias Hörtnagl <mathias.hoertnagl@gmail.comt> --
|
| 15 |
|
|
-- --
|
| 16 |
|
|
-- This program is free software: you can redistribute it and/or modify --
|
| 17 |
|
|
-- it under the terms of the GNU General Public License as published by --
|
| 18 |
|
|
-- the Free Software Foundation, either version 3 of the License, or --
|
| 19 |
|
|
-- (at your option) any later version. --
|
| 20 |
|
|
-- --
|
| 21 |
|
|
-- This program is distributed in the hope that it will be useful, --
|
| 22 |
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
|
| 23 |
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the --
|
| 24 |
|
|
-- GNU General Public License for more details. --
|
| 25 |
|
|
-- --
|
| 26 |
|
|
-- You should have received a copy of the GNU General Public License --
|
| 27 |
|
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>. --
|
| 28 |
|
|
--------------------------------------------------------------------------------
|
| 29 |
|
|
library ieee;
|
| 30 |
|
|
use ieee.std_logic_1164.all;
|
| 31 |
|
|
use ieee.numeric_std.all;
|
| 32 |
|
|
|
| 33 |
|
|
library work;
|
| 34 |
|
|
use work.iwb.all;
|
| 35 |
|
|
use work.icpu.all;
|
| 36 |
|
|
|
| 37 |
|
|
entity wbm is
|
| 38 |
|
|
port(
|
| 39 |
|
|
mi : in master_in_t;
|
| 40 |
|
|
mo : out master_out_t;
|
| 41 |
|
|
-- Non Wishbone Signals
|
| 42 |
|
|
ci : out cpu_in_t;
|
| 43 |
|
|
co : in cpu_out_t;
|
| 44 |
|
|
irq : in std_logic_vector(7 downto 0)
|
| 45 |
|
|
);
|
| 46 |
|
|
end wbm;
|
| 47 |
|
|
|
| 48 |
|
|
architecture rtl of wbm is
|
| 49 |
|
|
|
| 50 |
|
|
type state_t is (Init, I0, I1, I2, D0, D1, D2, Cpu);
|
| 51 |
|
|
|
| 52 |
|
|
type regs_t is
|
| 53 |
|
|
record
|
| 54 |
|
|
s : state_t;
|
| 55 |
|
|
i : std_logic_vector(31 downto 0);
|
| 56 |
|
|
d : std_logic_vector(31 downto 0);
|
| 57 |
|
|
end record;
|
| 58 |
|
|
|
| 59 |
|
|
constant regs_d : regs_t :=
|
| 60 |
|
|
regs_t'( Init, (others => '0'), (others => '0') );
|
| 61 |
|
|
|
| 62 |
|
|
signal r, rin : regs_t := regs_d;
|
| 63 |
|
|
begin
|
| 64 |
|
|
|
| 65 |
|
|
ci.clk <= mi.clk;
|
| 66 |
|
|
ci.rst <= mi.rst;
|
| 67 |
|
|
|
| 68 |
|
|
process(irq, r, co, mi.ack, mi.dat)
|
| 69 |
|
|
|
| 70 |
|
|
variable t2 : std_logic_vector(31 downto 0);
|
| 71 |
|
|
begin
|
| 72 |
|
|
|
| 73 |
|
|
rin <= r;
|
| 74 |
|
|
|
| 75 |
|
|
t2 := (others => '0');
|
| 76 |
|
|
|
| 77 |
|
|
ci.hld <= '1';
|
| 78 |
|
|
ci.ins <= (others => '0'); -- AREA: (others => '-');
|
| 79 |
|
|
ci.dat <= (others => '0'); -- AREA: (others => '-');
|
| 80 |
|
|
ci.irq <= irq;
|
| 81 |
|
|
|
| 82 |
|
|
mo.adr <= (others => '0'); -- AREA: (others => '-');
|
| 83 |
|
|
mo.dat <= (others => '0'); -- AREA: (others => '-');
|
| 84 |
|
|
mo.we <= '0';
|
| 85 |
|
|
mo.sel <= (others => '0');
|
| 86 |
|
|
mo.stb <= '0';
|
| 87 |
|
|
|
| 88 |
|
|
case r.s is
|
| 89 |
|
|
|
| 90 |
|
|
when Init =>
|
| 91 |
|
|
rin.s <= I0;
|
| 92 |
|
|
|
| 93 |
|
|
-----------------------------------------------------------------------
|
| 94 |
|
|
-- Instruction --
|
| 95 |
|
|
-----------------------------------------------------------------------
|
| 96 |
|
|
-- First stage of instruction fetch. Wait for memory device to be done
|
| 97 |
|
|
-- loading desired data.
|
| 98 |
|
|
when I0 =>
|
| 99 |
|
|
mo.adr <= co.iadr;
|
| 100 |
|
|
mo.sel <= "1111";
|
| 101 |
|
|
mo.stb <= '1';
|
| 102 |
|
|
if mi.ack = '1' then
|
| 103 |
|
|
--rin.i <= mi.dat;
|
| 104 |
|
|
rin.s <= I1;
|
| 105 |
|
|
end if;
|
| 106 |
|
|
|
| 107 |
|
|
-- Latch fetched instruction.
|
| 108 |
|
|
-- If co.sel is not null, there is data to be processed from the memory
|
| 109 |
|
|
-- stage. Else directly execute instruction.
|
| 110 |
|
|
when I1 =>
|
| 111 |
|
|
mo.adr <= co.iadr;
|
| 112 |
|
|
mo.sel <= "1111";
|
| 113 |
|
|
mo.stb <= '1';
|
| 114 |
|
|
rin.i <= mi.dat;
|
| 115 |
|
|
rin.s <= I2;
|
| 116 |
|
|
|
| 117 |
|
|
when I2 =>
|
| 118 |
|
|
if mi.ack = '0' then
|
| 119 |
|
|
if co.sel = x"0" then
|
| 120 |
|
|
rin.s <= Cpu;
|
| 121 |
|
|
else
|
| 122 |
|
|
rin.s <= D0;
|
| 123 |
|
|
end if;
|
| 124 |
|
|
end if;
|
| 125 |
|
|
|
| 126 |
|
|
-----------------------------------------------------------------------
|
| 127 |
|
|
-- Data --
|
| 128 |
|
|
-----------------------------------------------------------------------
|
| 129 |
|
|
-- Set data to be written to propper location on the 32bit bus,
|
| 130 |
|
|
-- according to co.sel.
|
| 131 |
|
|
-- Wait until I/O device is ready.
|
| 132 |
|
|
when D0 =>
|
| 133 |
|
|
mo.adr <= co.dadr;
|
| 134 |
|
|
case co.sel is
|
| 135 |
|
|
when "0001" => mo.dat(7 downto 0) <= co.dat(7 downto 0);
|
| 136 |
|
|
when "0010" => mo.dat(15 downto 8) <= co.dat(7 downto 0);
|
| 137 |
|
|
when "0100" => mo.dat(23 downto 16) <= co.dat(7 downto 0);
|
| 138 |
|
|
when "1000" => mo.dat(31 downto 24) <= co.dat(7 downto 0);
|
| 139 |
|
|
when "0011" => mo.dat(15 downto 0) <= co.dat(15 downto 0);
|
| 140 |
|
|
when "1100" => mo.dat(31 downto 16) <= co.dat(15 downto 0);
|
| 141 |
|
|
when others => mo.dat <= co.dat;
|
| 142 |
|
|
end case;
|
| 143 |
|
|
mo.we <= co.we;
|
| 144 |
|
|
mo.sel <= co.sel;
|
| 145 |
|
|
mo.stb <= '1';
|
| 146 |
|
|
if mi.ack = '1' then
|
| 147 |
|
|
rin.s <= D1;
|
| 148 |
|
|
end if;
|
| 149 |
|
|
|
| 150 |
|
|
-- Finish write cycle or latch read data.
|
| 151 |
|
|
when D1 =>
|
| 152 |
|
|
mo.adr <= co.dadr;
|
| 153 |
|
|
|
| 154 |
|
|
-- Read.
|
| 155 |
|
|
case co.sel is
|
| 156 |
|
|
when "0001" => t2(7 downto 0) := mi.dat(7 downto 0);
|
| 157 |
|
|
when "0010" => t2(7 downto 0) := mi.dat(15 downto 8);
|
| 158 |
|
|
when "0100" => t2(7 downto 0) := mi.dat(23 downto 16);
|
| 159 |
|
|
when "1000" => t2(7 downto 0) := mi.dat(31 downto 24);
|
| 160 |
|
|
when "0011" => t2(15 downto 0) := mi.dat(15 downto 0);
|
| 161 |
|
|
when "1100" => t2(15 downto 0) := mi.dat(31 downto 16);
|
| 162 |
|
|
when others => t2 := mi.dat;
|
| 163 |
|
|
end case;
|
| 164 |
|
|
|
| 165 |
|
|
-- Write.
|
| 166 |
|
|
case co.sel is
|
| 167 |
|
|
when "0001" => mo.dat(7 downto 0) <= co.dat(7 downto 0);
|
| 168 |
|
|
when "0010" => mo.dat(15 downto 8) <= co.dat(7 downto 0);
|
| 169 |
|
|
when "0100" => mo.dat(23 downto 16) <= co.dat(7 downto 0);
|
| 170 |
|
|
when "1000" => mo.dat(31 downto 24) <= co.dat(7 downto 0);
|
| 171 |
|
|
when "0011" => mo.dat(15 downto 0) <= co.dat(15 downto 0);
|
| 172 |
|
|
when "1100" => mo.dat(31 downto 16) <= co.dat(15 downto 0);
|
| 173 |
|
|
when others => mo.dat <= co.dat;
|
| 174 |
|
|
end case;
|
| 175 |
|
|
|
| 176 |
|
|
mo.we <= co.we;
|
| 177 |
|
|
mo.sel <= co.sel;
|
| 178 |
|
|
mo.stb <= '1';
|
| 179 |
|
|
rin.d <= t2;
|
| 180 |
|
|
rin.s <= D2;
|
| 181 |
|
|
|
| 182 |
|
|
when D2 =>
|
| 183 |
|
|
if mi.ack = '0' then
|
| 184 |
|
|
rin.s <= Cpu;
|
| 185 |
|
|
end if;
|
| 186 |
|
|
|
| 187 |
|
|
-----------------------------------------------------------------------
|
| 188 |
|
|
-- Run CPU --
|
| 189 |
|
|
-----------------------------------------------------------------------
|
| 190 |
|
|
-- Enable CPU and run it for one cycle, then at least fetch the next
|
| 191 |
|
|
-- instruction.
|
| 192 |
|
|
when Cpu =>
|
| 193 |
|
|
ci.hld <= '0';
|
| 194 |
|
|
ci.ins <= r.i;
|
| 195 |
|
|
ci.dat <= r.d;
|
| 196 |
|
|
rin.s <= I0;
|
| 197 |
|
|
end case;
|
| 198 |
|
|
end process;
|
| 199 |
|
|
|
| 200 |
|
|
reg : process(mi.clk)
|
| 201 |
|
|
begin
|
| 202 |
|
|
if rising_edge(mi.clk) then
|
| 203 |
|
|
if mi.rst = '1' then r <= regs_d; else r <= rin; end if;
|
| 204 |
|
|
end if;
|
| 205 |
|
|
end process;
|
| 206 |
|
|
end architecture;
|