1 |
2 |
AlexAntono |
-- ZPU
|
2 |
|
|
--
|
3 |
|
|
-- Copyright 2004-2008 oharboe - Øyvind Harboe - oyvind.harboe@zylin.com
|
4 |
|
|
--
|
5 |
|
|
-- The FreeBSD license
|
6 |
|
|
--
|
7 |
|
|
-- Redistribution and use in source and binary forms, with or without
|
8 |
|
|
-- modification, are permitted provided that the following conditions
|
9 |
|
|
-- are met:
|
10 |
|
|
--
|
11 |
|
|
-- 1. Redistributions of source code must retain the above copyright
|
12 |
|
|
-- notice, this list of conditions and the following disclaimer.
|
13 |
|
|
-- 2. Redistributions in binary form must reproduce the above
|
14 |
|
|
-- copyright notice, this list of conditions and the following
|
15 |
|
|
-- disclaimer in the documentation and/or other materials
|
16 |
|
|
-- provided with the distribution.
|
17 |
|
|
--
|
18 |
|
|
-- THIS SOFTWARE IS PROVIDED BY THE ZPU PROJECT ``AS IS'' AND ANY
|
19 |
|
|
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
20 |
|
|
-- THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
21 |
|
|
-- PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22 |
|
|
-- ZPU PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
23 |
|
|
-- INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
24 |
|
|
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
25 |
|
|
-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
26 |
|
|
-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
27 |
|
|
-- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28 |
|
|
-- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
29 |
|
|
-- ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
|
|
--
|
31 |
|
|
-- The views and conclusions contained in the software and documentation
|
32 |
|
|
-- are those of the authors and should not be interpreted as representing
|
33 |
|
|
-- official policies, either expressed or implied, of the ZPU Project.
|
34 |
|
|
|
35 |
|
|
library IEEE;
|
36 |
|
|
use IEEE.STD_LOGIC_1164.all;
|
37 |
|
|
use IEEE.STD_LOGIC_ARITH.all;
|
38 |
|
|
|
39 |
|
|
library work;
|
40 |
|
|
use work.zpu_config.all;
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
package zpupkg is
|
44 |
|
|
|
45 |
|
|
-- This bit is set for read/writes to IO
|
46 |
|
|
-- FIX!!! eventually this should be set to wordSize-1 so as to
|
47 |
|
|
-- to make the address of IO independent of amount of memory
|
48 |
|
|
-- reserved for CPU. Requires trivial tweaks in toolchain/runtime
|
49 |
|
|
-- libraries.
|
50 |
|
|
|
51 |
|
|
constant byteBits : integer := wordPower-3; -- # of bits in a word that addresses bytes
|
52 |
|
|
constant maxAddrBit : integer := maxAddrBitIncIO-1;
|
53 |
|
|
constant ioBit : integer := maxAddrBit+1;
|
54 |
|
|
constant wordSize : integer := 2**wordPower;
|
55 |
|
|
constant wordBytes : integer := wordSize/8;
|
56 |
|
|
constant minAddrBit : integer := byteBits;
|
57 |
|
|
-- configurable internal stack size. Probably going to be 16 after toolchain is done
|
58 |
|
|
constant stack_bits : integer := 5;
|
59 |
|
|
constant stack_size : integer := 2**stack_bits;
|
60 |
|
|
|
61 |
|
|
component dualport_ram is
|
62 |
|
|
port (clk : in std_logic;
|
63 |
|
|
memAWriteEnable : in std_logic;
|
64 |
|
|
memAAddr : in std_logic_vector(maxAddrBit downto minAddrBit);
|
65 |
|
|
memAWrite : in std_logic_vector(wordSize-1 downto 0);
|
66 |
|
|
memARead : out std_logic_vector(wordSize-1 downto 0);
|
67 |
|
|
memBWriteEnable : in std_logic;
|
68 |
|
|
memBAddr : in std_logic_vector(maxAddrBit downto minAddrBit);
|
69 |
|
|
memBWrite : in std_logic_vector(wordSize-1 downto 0);
|
70 |
|
|
memBRead : out std_logic_vector(wordSize-1 downto 0));
|
71 |
|
|
end component;
|
72 |
|
|
|
73 |
|
|
component dram is
|
74 |
|
|
port (clk : in std_logic;
|
75 |
|
|
areset : in std_logic;
|
76 |
|
|
mem_writeEnable : in std_logic;
|
77 |
|
|
mem_readEnable : in std_logic;
|
78 |
|
|
mem_addr : in std_logic_vector(maxAddrBit downto 0);
|
79 |
|
|
mem_write : in std_logic_vector(wordSize-1 downto 0);
|
80 |
|
|
mem_read : out std_logic_vector(wordSize-1 downto 0);
|
81 |
|
|
mem_busy : out std_logic;
|
82 |
|
|
mem_writeMask : in std_logic_vector(wordBytes-1 downto 0));
|
83 |
|
|
end component;
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
component trace is
|
87 |
|
|
port(
|
88 |
|
|
clk : in std_logic;
|
89 |
|
|
begin_inst : in std_logic;
|
90 |
|
|
pc : in std_logic_vector(maxAddrBitIncIO downto 0);
|
91 |
|
|
opcode : in std_logic_vector(7 downto 0);
|
92 |
|
|
sp : in std_logic_vector(maxAddrBitIncIO downto minAddrBit);
|
93 |
|
|
memA : in std_logic_vector(wordSize-1 downto 0);
|
94 |
|
|
memB : in std_logic_vector(wordSize-1 downto 0);
|
95 |
|
|
busy : in std_logic;
|
96 |
|
|
intSp : in std_logic_vector(stack_bits-1 downto 0)
|
97 |
|
|
);
|
98 |
|
|
end component;
|
99 |
|
|
|
100 |
|
|
component zpu_core is
|
101 |
|
|
generic (stack_address : integer := 1016);
|
102 |
|
|
port ( clk : in std_logic;
|
103 |
|
|
sreset : in std_logic;
|
104 |
|
|
enable : in std_logic;
|
105 |
|
|
pc_bo : out std_logic_vector(31 downto 0);
|
106 |
|
|
|
107 |
|
|
mem_req : out std_logic;
|
108 |
|
|
mem_we : out std_logic;
|
109 |
|
|
mem_ack : in std_logic;
|
110 |
|
|
mem_read : in std_logic_vector(wordSize-1 downto 0);
|
111 |
|
|
mem_write : out std_logic_vector(wordSize-1 downto 0);
|
112 |
|
|
out_mem_addr : out std_logic_vector(maxAddrBitIncIO downto 0);
|
113 |
|
|
mem_writeMask: out std_logic_vector(wordBytes-1 downto 0);
|
114 |
|
|
|
115 |
|
|
interrupt : in std_logic;
|
116 |
|
|
interrupt_ack : out std_logic;
|
117 |
|
|
break_o : out std_logic;
|
118 |
|
|
zpu_status : out std_logic_vector(63 downto 0));
|
119 |
|
|
end component;
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
component timer is
|
124 |
|
|
port(
|
125 |
|
|
clk : in std_logic;
|
126 |
|
|
areset : in std_logic;
|
127 |
|
|
sample : in std_logic;
|
128 |
|
|
reset : in std_logic;
|
129 |
|
|
counter : out std_logic_vector(63 downto 0));
|
130 |
|
|
end component;
|
131 |
|
|
|
132 |
|
|
component zpuio is
|
133 |
|
|
port ( areset : in std_logic;
|
134 |
|
|
cpu_clk : in std_logic;
|
135 |
|
|
clk_status : in std_logic_vector(2 downto 0);
|
136 |
|
|
cpu_din : in std_logic_vector(15 downto 0);
|
137 |
|
|
cpu_a : in std_logic_vector(20 downto 0);
|
138 |
|
|
cpu_we : in std_logic_vector(1 downto 0);
|
139 |
|
|
cpu_re : in std_logic;
|
140 |
|
|
cpu_dout : inout std_logic_vector(15 downto 0));
|
141 |
|
|
end component;
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
-- opcode decode constants
|
147 |
|
|
constant OpCode_Im : std_logic_vector(7 downto 7) := "1";
|
148 |
|
|
constant OpCode_StoreSP : std_logic_vector(7 downto 5) := "010";
|
149 |
|
|
constant OpCode_LoadSP : std_logic_vector(7 downto 5) := "011";
|
150 |
|
|
constant OpCode_Emulate : std_logic_vector(7 downto 5) := "001";
|
151 |
|
|
constant OpCode_AddSP : std_logic_vector(7 downto 4) := "0001";
|
152 |
|
|
constant OpCode_Short : std_logic_vector(7 downto 4) := "0000";
|
153 |
|
|
|
154 |
|
|
constant OpCode_Break : std_logic_vector(3 downto 0) := "0000";
|
155 |
|
|
constant OpCode_Shiftleft: std_logic_vector(3 downto 0) := "0001";
|
156 |
|
|
constant OpCode_PushSP : std_logic_vector(3 downto 0) := "0010";
|
157 |
|
|
constant OpCode_PushInt : std_logic_vector(3 downto 0) := "0011";
|
158 |
|
|
|
159 |
|
|
constant OpCode_PopPC : std_logic_vector(3 downto 0) := "0100";
|
160 |
|
|
constant OpCode_Add : std_logic_vector(3 downto 0) := "0101";
|
161 |
|
|
constant OpCode_And : std_logic_vector(3 downto 0) := "0110";
|
162 |
|
|
constant OpCode_Or : std_logic_vector(3 downto 0) := "0111";
|
163 |
|
|
|
164 |
|
|
constant OpCode_Load : std_logic_vector(3 downto 0) := "1000";
|
165 |
|
|
constant OpCode_Not : std_logic_vector(3 downto 0) := "1001";
|
166 |
|
|
constant OpCode_Flip : std_logic_vector(3 downto 0) := "1010";
|
167 |
|
|
constant OpCode_Nop : std_logic_vector(3 downto 0) := "1011";
|
168 |
|
|
|
169 |
|
|
constant OpCode_Store : std_logic_vector(3 downto 0) := "1100";
|
170 |
|
|
constant OpCode_PopSP : std_logic_vector(3 downto 0) := "1101";
|
171 |
|
|
constant OpCode_Compare : std_logic_vector(3 downto 0) := "1110";
|
172 |
|
|
constant OpCode_PopInt : std_logic_vector(3 downto 0) := "1111";
|
173 |
|
|
|
174 |
|
|
constant OpCode_Lessthan : std_logic_vector(5 downto 0) := conv_std_logic_vector(36, 6);
|
175 |
|
|
constant OpCode_Lessthanorequal : std_logic_vector(5 downto 0) := conv_std_logic_vector(37, 6);
|
176 |
|
|
constant OpCode_Ulessthan : std_logic_vector(5 downto 0) := conv_std_logic_vector(38, 6);
|
177 |
|
|
constant OpCode_Ulessthanorequal : std_logic_vector(5 downto 0) := conv_std_logic_vector(39, 6);
|
178 |
|
|
|
179 |
|
|
constant OpCode_Swap : std_logic_vector(5 downto 0) := conv_std_logic_vector(40, 6);
|
180 |
|
|
constant OpCode_Mult : std_logic_vector(5 downto 0) := conv_std_logic_vector(41, 6);
|
181 |
|
|
|
182 |
|
|
constant OpCode_Lshiftright : std_logic_vector(5 downto 0) := conv_std_logic_vector(42, 6);
|
183 |
|
|
constant OpCode_Ashiftleft : std_logic_vector(5 downto 0) := conv_std_logic_vector(43, 6);
|
184 |
|
|
constant OpCode_Ashiftright : std_logic_vector(5 downto 0) := conv_std_logic_vector(44, 6);
|
185 |
|
|
constant OpCode_Call : std_logic_vector(5 downto 0) := conv_std_logic_vector(45, 6);
|
186 |
|
|
|
187 |
|
|
constant OpCode_Eq : std_logic_vector(5 downto 0) := conv_std_logic_vector(46, 6);
|
188 |
|
|
constant OpCode_Neq : std_logic_vector(5 downto 0) := conv_std_logic_vector(47, 6);
|
189 |
|
|
|
190 |
|
|
constant OpCode_Sub : std_logic_vector(5 downto 0) := conv_std_logic_vector(49, 6);
|
191 |
|
|
constant OpCode_Loadb : std_logic_vector(5 downto 0) := conv_std_logic_vector(51, 6);
|
192 |
|
|
constant OpCode_Storeb : std_logic_vector(5 downto 0) := conv_std_logic_vector(52, 6);
|
193 |
|
|
|
194 |
|
|
constant OpCode_Eqbranch : std_logic_vector(5 downto 0) := conv_std_logic_vector(55, 6);
|
195 |
|
|
constant OpCode_Neqbranch : std_logic_vector(5 downto 0) := conv_std_logic_vector(56, 6);
|
196 |
|
|
constant OpCode_Poppcrel : std_logic_vector(5 downto 0) := conv_std_logic_vector(57, 6);
|
197 |
|
|
|
198 |
|
|
constant OpCode_Pushspadd : std_logic_vector(5 downto 0) := conv_std_logic_vector(61, 6);
|
199 |
|
|
constant OpCode_Mult16x16 : std_logic_vector(5 downto 0) := conv_std_logic_vector(62, 6);
|
200 |
|
|
constant OpCode_Callpcrel : std_logic_vector(5 downto 0) := conv_std_logic_vector(63, 6);
|
201 |
|
|
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
constant OpCode_Size : integer := 8;
|
205 |
|
|
|
206 |
|
|
|
207 |
|
|
|
208 |
|
|
end zpupkg;
|