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

Subversion Repositories ion

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

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 12 ja_rd
-- 32-cycle mul/div module control. Bits 4-3 & 1-0 of IR.
100
subtype t_mult_function is std_logic_vector(3 downto 0);
101
constant MULT_NOTHING       : t_mult_function := "0000";
102
constant MULT_READ_LO       : t_mult_function := "1010"; -- 18
103
constant MULT_READ_HI       : t_mult_function := "1000"; -- 16
104
constant MULT_WRITE_LO      : t_mult_function := "1011"; -- 19
105
constant MULT_WRITE_HI      : t_mult_function := "1001"; -- 17
106
constant MULT_MULT          : t_mult_function := "1101"; -- 25
107
constant MULT_SIGNED_MULT   : t_mult_function := "1100"; -- 24
108
constant MULT_DIVIDE        : t_mult_function := "1111"; -- 26
109
constant MULT_SIGNED_DIVIDE : t_mult_function := "1110"; -- 27
110
 
111 37 ja_rd
-- Computes ceil(log2(A)), e.g. address width of memory block
112
-- CAN BE USED IN SYNTHESIZABLE CODE as long as called with constant arguments
113
function log2(A : natural) return natural;
114 12 ja_rd
 
115 64 ja_rd
-- Decodes a memory address, gives the type of memory
116
-- CAN BE USED IN SYNTHESIZABLE CODE, argument does not need to be constant
117
function decode_addr(addr : t_addr_decode) return t_range_attr;
118 37 ja_rd
 
119 64 ja_rd
 
120 2 ja_rd
end package;
121 37 ja_rd
 
122
package body mips_pkg is
123
 
124
function log2(A : natural) return natural is
125
begin
126
    for I in 1 to 30 loop -- Works for up to 32 bit integers
127 85 ja_rd
        if(2**I >= A) then
128
            return(I);
129 37 ja_rd
        end if;
130
    end loop;
131
    return(30);
132
end function log2;
133
 
134 64 ja_rd
-- Address decoding for Plasma-like system
135
function decode_addr_plasma(addr : t_addr_decode) return t_range_attr is
136
begin
137
 
138
    case addr(31 downto 27) is
139 72 ja_rd
    when "00000"    => return (MT_BRAM     ,'0','0',"000"); -- useg
140
    when "10000"    => return (MT_SRAM_16B ,'1','1',"000"); -- kseg0
141
    when "00100"    => return (MT_IO_SYNC  ,'1','0',"000"); -- kseg1 i/o
142
    when others     => return (MT_UNMAPPED ,'0','0',"000"); -- stray
143 64 ja_rd
    end case;
144
 
145
end function decode_addr_plasma;
146
 
147 75 ja_rd
-- Address decoding for MIPS-I-like system as implemented in target hardware
148 64 ja_rd
function decode_addr_mips1(addr : t_addr_decode) return t_range_attr is
149
begin
150
 
151
    case addr(31 downto 27) is
152 81 ja_rd
    when "00000"    => return (MT_SRAM_16B ,'1','1',"001"); -- useg
153 72 ja_rd
    when "10000"    => return (MT_SRAM_16B ,'1','1',"000"); -- kseg0
154
    --when "10100"    => return (MT_IO_SYNC  ,'1','0',"000"); -- kseg1 i/o
155
    when "00100"    => return (MT_IO_SYNC  ,'1','0',"000"); -- kseg1 i/o
156 75 ja_rd
    when "10110"    => return (MT_SRAM_8B  ,'0','0',"011"); -- kseg1 flash
157 72 ja_rd
    when "10111"    => return (MT_BRAM     ,'0','0',"000"); -- kseg1 boot rom
158
    when others     => return (MT_UNMAPPED ,'0','0',"000"); -- stray
159 64 ja_rd
    end case;
160
 
161
end function decode_addr_mips1;
162
 
163
 
164
function decode_addr(addr : t_addr_decode) return t_range_attr is
165
begin
166
    if USE_MIPS1_ADDR_MAP then
167
        return decode_addr_mips1(addr);
168
    else
169
        return decode_addr_plasma(addr);
170
    end if;
171
 
172
end function decode_addr;
173
 
174 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.