1 |
64 |
ja_rd |
--------------------------------------------------------------------------------
|
2 |
|
|
-- mips_pkg.vhdl -- Configuration constants & utility types and functions
|
3 |
|
|
--------------------------------------------------------------------------------
|
4 |
|
|
-- IMPORTANT:
|
5 |
|
|
-- Here's where you define the memory map of the system, in the implementation
|
6 |
|
|
-- of function decode_addr.
|
7 |
|
|
-- You need to change that function to change the memory map, independent of any
|
8 |
|
|
-- additional address decoding you may do out of the FPGA (e.g. if you have more
|
9 |
|
|
-- than one chip on any data bus) or out of the MCU module (e.g. when you add
|
10 |
|
|
-- new IO registers).
|
11 |
|
|
-- Please see the module c2sb_demo and mips_mcu for examples of memory decoding.
|
12 |
|
|
--------------------------------------------------------------------------------
|
13 |
162 |
ja_rd |
-- Copyright (C) 2011 Jose A. Ruiz
|
14 |
161 |
ja_rd |
--
|
15 |
|
|
-- This source file may be used and distributed without
|
16 |
|
|
-- restriction provided that this copyright statement is not
|
17 |
|
|
-- removed from the file and that any derivative work contains
|
18 |
|
|
-- the original copyright notice and the associated disclaimer.
|
19 |
|
|
--
|
20 |
|
|
-- This source file is free software; you can redistribute it
|
21 |
|
|
-- and/or modify it under the terms of the GNU Lesser General
|
22 |
|
|
-- Public License as published by the Free Software Foundation;
|
23 |
|
|
-- either version 2.1 of the License, or (at your option) any
|
24 |
|
|
-- later version.
|
25 |
|
|
--
|
26 |
|
|
-- This source is distributed in the hope that it will be
|
27 |
|
|
-- useful, but WITHOUT ANY WARRANTY; without even the implied
|
28 |
|
|
-- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
29 |
|
|
-- PURPOSE. See the GNU Lesser General Public License for more
|
30 |
|
|
-- details.
|
31 |
|
|
--
|
32 |
|
|
-- You should have received a copy of the GNU Lesser General
|
33 |
|
|
-- Public License along with this source; if not, download it
|
34 |
|
|
-- from http://www.opencores.org/lgpl.shtml
|
35 |
|
|
--------------------------------------------------------------------------------
|
36 |
64 |
ja_rd |
|
37 |
2 |
ja_rd |
library ieee;
|
38 |
|
|
use ieee.std_logic_1164.all;
|
39 |
|
|
use ieee.std_logic_arith.all;
|
40 |
|
|
use ieee.std_logic_unsigned.all;
|
41 |
|
|
|
42 |
|
|
package mips_pkg is
|
43 |
|
|
|
44 |
64 |
ja_rd |
---- Basic types ---------------------------------------------------------------
|
45 |
|
|
|
46 |
|
|
subtype t_word is std_logic_vector(31 downto 0);
|
47 |
|
|
|
48 |
|
|
|
49 |
|
|
---- System configuration constants --------------------------------------------
|
50 |
|
|
|
51 |
|
|
-- True to use standard-ish MIPS-1 memory map, false to use Plasma's
|
52 |
|
|
-- (see implementation of function decode_addr below).
|
53 |
|
|
constant USE_MIPS1_ADDR_MAP : boolean := true;
|
54 |
|
|
|
55 |
|
|
-- Reset vector address minus 4 (0xfffffffc for Plasma, 0xbfbffffc for mips1)
|
56 |
|
|
constant RESET_VECTOR_M4 : t_word := X"bfbffffc";
|
57 |
|
|
|
58 |
|
|
-- Trap vector address (0x0000003c for Plasma, 0xbfc00180 for mips1)
|
59 |
|
|
constant TRAP_VECTOR : t_word := X"bfc00180";
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
---- Address decoding ----------------------------------------------------------
|
63 |
|
|
|
64 |
|
|
-- Note: it is the cache module that does all internal address decoding --------
|
65 |
|
|
|
66 |
|
|
-- This is the slice of the address that will be used to decode memory areas
|
67 |
48 |
ja_rd |
subtype t_addr_decode is std_logic_vector(31 downto 24);
|
68 |
37 |
ja_rd |
|
69 |
64 |
ja_rd |
-- Part of the memory area attribute: the type of memory determines how the
|
70 |
|
|
-- cache module handles each block
|
71 |
72 |
ja_rd |
subtype t_memory_type is std_logic_vector(7 downto 5);
|
72 |
64 |
ja_rd |
-- These are all the types the cache knows about
|
73 |
|
|
constant MT_BRAM : t_memory_type := "000";
|
74 |
|
|
constant MT_IO_SYNC : t_memory_type := "001";
|
75 |
|
|
constant MT_SRAM_16B : t_memory_type := "010";
|
76 |
75 |
ja_rd |
constant MT_SRAM_8B : t_memory_type := "011";
|
77 |
64 |
ja_rd |
constant MT_DDR_16B : t_memory_type := "100";
|
78 |
|
|
constant MT_UNMAPPED : t_memory_type := "111";
|
79 |
37 |
ja_rd |
|
80 |
72 |
ja_rd |
-- Wait state counter -- we're supporting static memory from 10 to >100 ns
|
81 |
|
|
subtype t_wait_state_count is std_logic_vector(2 downto 0);
|
82 |
64 |
ja_rd |
|
83 |
72 |
ja_rd |
-- 'Attributes' of some memory block -- used when decoding memory addresses
|
84 |
|
|
type t_range_attr is record
|
85 |
|
|
mem_type : t_memory_type;
|
86 |
|
|
writeable : std_logic;
|
87 |
|
|
cacheable : std_logic;
|
88 |
|
|
wait_states : t_wait_state_count;
|
89 |
|
|
end record t_range_attr;
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
64 |
ja_rd |
---- More basic types and constants --------------------------------------------
|
94 |
|
|
|
95 |
2 |
ja_rd |
subtype t_addr is std_logic_vector(31 downto 0);
|
96 |
|
|
subtype t_dword is std_logic_vector(63 downto 0);
|
97 |
|
|
subtype t_regnum is std_logic_vector(4 downto 0);
|
98 |
|
|
type t_rbank is array(0 to 31) of t_word;
|
99 |
|
|
subtype t_pc is std_logic_vector(31 downto 2);
|
100 |
64 |
ja_rd |
-- This is used as a textual shortcut only
|
101 |
2 |
ja_rd |
constant ZERO : t_word := (others => '0');
|
102 |
64 |
ja_rd |
-- control word for ALU
|
103 |
2 |
ja_rd |
type t_alu_control is record
|
104 |
|
|
logic_sel : std_logic_vector(1 downto 0);
|
105 |
|
|
shift_sel : std_logic_vector(1 downto 0);
|
106 |
|
|
shift_amount : std_logic_vector(4 downto 0);
|
107 |
|
|
neg_sel : std_logic_vector(1 downto 0);
|
108 |
|
|
use_arith : std_logic;
|
109 |
|
|
use_logic : std_logic_vector(1 downto 0);
|
110 |
|
|
cy_in : std_logic;
|
111 |
|
|
use_slt : std_logic;
|
112 |
|
|
arith_unsigned : std_logic;
|
113 |
|
|
end record t_alu_control;
|
114 |
64 |
ja_rd |
-- Flags coming from the ALU
|
115 |
2 |
ja_rd |
type t_alu_flags is record
|
116 |
|
|
inp1_lt_zero : std_logic;
|
117 |
|
|
inp1_eq_zero : std_logic;
|
118 |
|
|
inp1_lt_inp2 : std_logic;
|
119 |
|
|
inp1_eq_inp2 : std_logic;
|
120 |
|
|
end record t_alu_flags;
|
121 |
|
|
|
122 |
134 |
ja_rd |
-- Debug info output by sinthesizable MPU core; meant to debug the core itself,
|
123 |
|
|
-- not to debug software!
|
124 |
|
|
type t_debug_info is record
|
125 |
|
|
cache_enabled : std_logic;
|
126 |
|
|
unmapped_access : std_logic;
|
127 |
|
|
end record t_debug_info;
|
128 |
|
|
|
129 |
|
|
|
130 |
12 |
ja_rd |
-- 32-cycle mul/div module control. Bits 4-3 & 1-0 of IR.
|
131 |
|
|
subtype t_mult_function is std_logic_vector(3 downto 0);
|
132 |
|
|
constant MULT_NOTHING : t_mult_function := "0000";
|
133 |
|
|
constant MULT_READ_LO : t_mult_function := "1010"; -- 18
|
134 |
|
|
constant MULT_READ_HI : t_mult_function := "1000"; -- 16
|
135 |
|
|
constant MULT_WRITE_LO : t_mult_function := "1011"; -- 19
|
136 |
|
|
constant MULT_WRITE_HI : t_mult_function := "1001"; -- 17
|
137 |
|
|
constant MULT_MULT : t_mult_function := "1101"; -- 25
|
138 |
|
|
constant MULT_SIGNED_MULT : t_mult_function := "1100"; -- 24
|
139 |
|
|
constant MULT_DIVIDE : t_mult_function := "1111"; -- 26
|
140 |
|
|
constant MULT_SIGNED_DIVIDE : t_mult_function := "1110"; -- 27
|
141 |
|
|
|
142 |
37 |
ja_rd |
-- Computes ceil(log2(A)), e.g. address width of memory block
|
143 |
|
|
-- CAN BE USED IN SYNTHESIZABLE CODE as long as called with constant arguments
|
144 |
|
|
function log2(A : natural) return natural;
|
145 |
12 |
ja_rd |
|
146 |
64 |
ja_rd |
-- Decodes a memory address, gives the type of memory
|
147 |
|
|
-- CAN BE USED IN SYNTHESIZABLE CODE, argument does not need to be constant
|
148 |
|
|
function decode_addr(addr : t_addr_decode) return t_range_attr;
|
149 |
37 |
ja_rd |
|
150 |
64 |
ja_rd |
|
151 |
2 |
ja_rd |
end package;
|
152 |
37 |
ja_rd |
|
153 |
|
|
package body mips_pkg is
|
154 |
|
|
|
155 |
|
|
function log2(A : natural) return natural is
|
156 |
|
|
begin
|
157 |
|
|
for I in 1 to 30 loop -- Works for up to 32 bit integers
|
158 |
85 |
ja_rd |
if(2**I >= A) then
|
159 |
|
|
return(I);
|
160 |
37 |
ja_rd |
end if;
|
161 |
|
|
end loop;
|
162 |
|
|
return(30);
|
163 |
|
|
end function log2;
|
164 |
|
|
|
165 |
64 |
ja_rd |
-- Address decoding for Plasma-like system
|
166 |
|
|
function decode_addr_plasma(addr : t_addr_decode) return t_range_attr is
|
167 |
|
|
begin
|
168 |
|
|
|
169 |
|
|
case addr(31 downto 27) is
|
170 |
72 |
ja_rd |
when "00000" => return (MT_BRAM ,'0','0',"000"); -- useg
|
171 |
|
|
when "10000" => return (MT_SRAM_16B ,'1','1',"000"); -- kseg0
|
172 |
|
|
when "00100" => return (MT_IO_SYNC ,'1','0',"000"); -- kseg1 i/o
|
173 |
|
|
when others => return (MT_UNMAPPED ,'0','0',"000"); -- stray
|
174 |
64 |
ja_rd |
end case;
|
175 |
|
|
|
176 |
|
|
end function decode_addr_plasma;
|
177 |
|
|
|
178 |
75 |
ja_rd |
-- Address decoding for MIPS-I-like system as implemented in target hardware
|
179 |
64 |
ja_rd |
function decode_addr_mips1(addr : t_addr_decode) return t_range_attr is
|
180 |
|
|
begin
|
181 |
|
|
|
182 |
|
|
case addr(31 downto 27) is
|
183 |
120 |
ja_rd |
when "00000" => return (MT_SRAM_16B ,'1','1',"010"); -- useg
|
184 |
|
|
when "10000" => return (MT_SRAM_16B ,'1','1',"010"); -- kseg0
|
185 |
72 |
ja_rd |
--when "10100" => return (MT_IO_SYNC ,'1','0',"000"); -- kseg1 i/o
|
186 |
|
|
when "00100" => return (MT_IO_SYNC ,'1','0',"000"); -- kseg1 i/o
|
187 |
120 |
ja_rd |
when "10110" => return (MT_SRAM_8B ,'0','0',"111"); -- kseg1 flash
|
188 |
72 |
ja_rd |
when "10111" => return (MT_BRAM ,'0','0',"000"); -- kseg1 boot rom
|
189 |
|
|
when others => return (MT_UNMAPPED ,'0','0',"000"); -- stray
|
190 |
64 |
ja_rd |
end case;
|
191 |
|
|
|
192 |
|
|
end function decode_addr_mips1;
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
function decode_addr(addr : t_addr_decode) return t_range_attr is
|
196 |
|
|
begin
|
197 |
|
|
if USE_MIPS1_ADDR_MAP then
|
198 |
|
|
return decode_addr_mips1(addr);
|
199 |
|
|
else
|
200 |
|
|
return decode_addr_plasma(addr);
|
201 |
|
|
end if;
|
202 |
|
|
|
203 |
|
|
end function decode_addr;
|
204 |
|
|
|
205 |
37 |
ja_rd |
end package body;
|