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

Subversion Repositories ion

[/] [ion/] [trunk/] [vhdl/] [mips_pkg.vhdl] - Blame information for rev 150

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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
 
14 2 ja_rd
library ieee;
15
use ieee.std_logic_1164.all;
16
use ieee.std_logic_arith.all;
17
use ieee.std_logic_unsigned.all;
18
 
19
package mips_pkg is
20
 
21 64 ja_rd
---- Basic types ---------------------------------------------------------------
22
 
23
subtype t_word is std_logic_vector(31 downto 0);
24
 
25
 
26
---- System configuration constants --------------------------------------------
27
 
28
-- True to use standard-ish MIPS-1 memory map, false to use Plasma's
29
-- (see implementation of function decode_addr below).
30
constant USE_MIPS1_ADDR_MAP : boolean := true;
31
 
32
-- Reset vector address minus 4 (0xfffffffc for Plasma, 0xbfbffffc for mips1)
33
constant RESET_VECTOR_M4 : t_word   := X"bfbffffc";
34
 
35
-- Trap vector address (0x0000003c for Plasma, 0xbfc00180 for mips1)
36
constant TRAP_VECTOR : t_word       := X"bfc00180";
37
 
38
 
39
---- Address decoding ----------------------------------------------------------
40
 
41
-- Note: it is the cache module that does all internal address decoding --------
42
 
43
-- This is the slice of the address that will be used to decode memory areas
44 48 ja_rd
subtype t_addr_decode is std_logic_vector(31 downto 24);
45 37 ja_rd
 
46 64 ja_rd
-- Part of the memory area attribute: the type of memory determines how the
47
-- cache module handles each block
48 72 ja_rd
subtype t_memory_type is std_logic_vector(7 downto 5);
49 64 ja_rd
-- These are all the types the cache knows about
50
constant MT_BRAM : t_memory_type            := "000";
51
constant MT_IO_SYNC : t_memory_type         := "001";
52
constant MT_SRAM_16B : t_memory_type        := "010";
53 75 ja_rd
constant MT_SRAM_8B : t_memory_type         := "011";
54 64 ja_rd
constant MT_DDR_16B : t_memory_type         := "100";
55
constant MT_UNMAPPED : t_memory_type        := "111";
56 37 ja_rd
 
57 72 ja_rd
-- Wait state counter -- we're supporting static memory from 10 to >100 ns
58
subtype t_wait_state_count is std_logic_vector(2 downto 0);
59 64 ja_rd
 
60 72 ja_rd
-- 'Attributes' of some memory block -- used when decoding memory addresses
61
type t_range_attr is record
62
    mem_type :          t_memory_type;
63
    writeable :         std_logic;
64
    cacheable :         std_logic;
65
    wait_states :       t_wait_state_count;
66
end record t_range_attr;
67
 
68
 
69
 
70 64 ja_rd
---- More basic types and constants --------------------------------------------
71
 
72 2 ja_rd
subtype t_addr is std_logic_vector(31 downto 0);
73
subtype t_dword is std_logic_vector(63 downto 0);
74
subtype t_regnum is std_logic_vector(4 downto 0);
75
type t_rbank is array(0 to 31) of t_word;
76
subtype t_pc is std_logic_vector(31 downto 2);
77 64 ja_rd
-- This is used as a textual shortcut only
78 2 ja_rd
constant ZERO : t_word := (others => '0');
79 64 ja_rd
-- control word for ALU
80 2 ja_rd
type t_alu_control is record
81
    logic_sel :         std_logic_vector(1 downto 0);
82
    shift_sel :         std_logic_vector(1 downto 0);
83
    shift_amount :      std_logic_vector(4 downto 0);
84
    neg_sel :           std_logic_vector(1 downto 0);
85
    use_arith :         std_logic;
86
    use_logic :         std_logic_vector(1 downto 0);
87
    cy_in :             std_logic;
88
    use_slt :           std_logic;
89
    arith_unsigned :    std_logic;
90
end record t_alu_control;
91 64 ja_rd
-- Flags coming from the ALU
92 2 ja_rd
type t_alu_flags is record
93
    inp1_lt_zero :      std_logic;
94
    inp1_eq_zero :      std_logic;
95
    inp1_lt_inp2 :      std_logic;
96
    inp1_eq_inp2 :      std_logic;
97
end record t_alu_flags;
98
 
99 134 ja_rd
-- Debug info output by sinthesizable MPU core; meant to debug the core itself, 
100
-- not to debug software!
101
type t_debug_info is record
102
    cache_enabled :     std_logic;
103
    unmapped_access :   std_logic;
104
end record t_debug_info;
105
 
106
 
107 12 ja_rd
-- 32-cycle mul/div module control. Bits 4-3 & 1-0 of IR.
108
subtype t_mult_function is std_logic_vector(3 downto 0);
109
constant MULT_NOTHING       : t_mult_function := "0000";
110
constant MULT_READ_LO       : t_mult_function := "1010"; -- 18
111
constant MULT_READ_HI       : t_mult_function := "1000"; -- 16
112
constant MULT_WRITE_LO      : t_mult_function := "1011"; -- 19
113
constant MULT_WRITE_HI      : t_mult_function := "1001"; -- 17
114
constant MULT_MULT          : t_mult_function := "1101"; -- 25
115
constant MULT_SIGNED_MULT   : t_mult_function := "1100"; -- 24
116
constant MULT_DIVIDE        : t_mult_function := "1111"; -- 26
117
constant MULT_SIGNED_DIVIDE : t_mult_function := "1110"; -- 27
118
 
119 37 ja_rd
-- Computes ceil(log2(A)), e.g. address width of memory block
120
-- CAN BE USED IN SYNTHESIZABLE CODE as long as called with constant arguments
121
function log2(A : natural) return natural;
122 12 ja_rd
 
123 64 ja_rd
-- Decodes a memory address, gives the type of memory
124
-- CAN BE USED IN SYNTHESIZABLE CODE, argument does not need to be constant
125
function decode_addr(addr : t_addr_decode) return t_range_attr;
126 37 ja_rd
 
127 64 ja_rd
 
128 2 ja_rd
end package;
129 37 ja_rd
 
130
package body mips_pkg is
131
 
132
function log2(A : natural) return natural is
133
begin
134
    for I in 1 to 30 loop -- Works for up to 32 bit integers
135 85 ja_rd
        if(2**I >= A) then
136
            return(I);
137 37 ja_rd
        end if;
138
    end loop;
139
    return(30);
140
end function log2;
141
 
142 64 ja_rd
-- Address decoding for Plasma-like system
143
function decode_addr_plasma(addr : t_addr_decode) return t_range_attr is
144
begin
145
 
146
    case addr(31 downto 27) is
147 72 ja_rd
    when "00000"    => return (MT_BRAM     ,'0','0',"000"); -- useg
148
    when "10000"    => return (MT_SRAM_16B ,'1','1',"000"); -- kseg0
149
    when "00100"    => return (MT_IO_SYNC  ,'1','0',"000"); -- kseg1 i/o
150
    when others     => return (MT_UNMAPPED ,'0','0',"000"); -- stray
151 64 ja_rd
    end case;
152
 
153
end function decode_addr_plasma;
154
 
155 75 ja_rd
-- Address decoding for MIPS-I-like system as implemented in target hardware
156 64 ja_rd
function decode_addr_mips1(addr : t_addr_decode) return t_range_attr is
157
begin
158
 
159
    case addr(31 downto 27) is
160 120 ja_rd
    when "00000"    => return (MT_SRAM_16B ,'1','1',"010"); -- useg
161
    when "10000"    => return (MT_SRAM_16B ,'1','1',"010"); -- kseg0
162 72 ja_rd
    --when "10100"    => return (MT_IO_SYNC  ,'1','0',"000"); -- kseg1 i/o
163
    when "00100"    => return (MT_IO_SYNC  ,'1','0',"000"); -- kseg1 i/o
164 120 ja_rd
    when "10110"    => return (MT_SRAM_8B  ,'0','0',"111"); -- kseg1 flash
165 72 ja_rd
    when "10111"    => return (MT_BRAM     ,'0','0',"000"); -- kseg1 boot rom
166
    when others     => return (MT_UNMAPPED ,'0','0',"000"); -- stray
167 64 ja_rd
    end case;
168
 
169
end function decode_addr_mips1;
170
 
171
 
172
function decode_addr(addr : t_addr_decode) return t_range_attr is
173
begin
174
    if USE_MIPS1_ADDR_MAP then
175
        return decode_addr_mips1(addr);
176
    else
177
        return decode_addr_plasma(addr);
178
    end if;
179
 
180
end function decode_addr;
181
 
182 37 ja_rd
end package body;

powered by: WebSVN 2.1.0

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