1 |
185 |
jshamlet |
-- Copyright (c)2006,2011,2012,2013,2015,2020 Jeremy Seth Henry
|
2 |
181 |
jshamlet |
-- All rights reserved.
|
3 |
|
|
--
|
4 |
|
|
-- Redistribution and use in source and binary forms, with or without
|
5 |
|
|
-- modification, are permitted provided that the following conditions are met:
|
6 |
|
|
-- * Redistributions of source code must retain the above copyright
|
7 |
|
|
-- notice, this list of conditions and the following disclaimer.
|
8 |
|
|
-- * Redistributions in binary form must reproduce the above copyright
|
9 |
|
|
-- notice, this list of conditions and the following disclaimer in the
|
10 |
|
|
-- documentation and/or other materials provided with the distribution,
|
11 |
|
|
-- where applicable (as part of a user interface, debugging port, etc.)
|
12 |
|
|
--
|
13 |
|
|
-- THIS SOFTWARE IS PROVIDED BY JEREMY SETH HENRY ``AS IS'' AND ANY
|
14 |
|
|
-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15 |
|
|
-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16 |
|
|
-- DISCLAIMED. IN NO EVENT SHALL JEREMY SETH HENRY BE LIABLE FOR ANY
|
17 |
|
|
-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18 |
|
|
-- (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19 |
|
|
-- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20 |
|
|
-- ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21 |
220 |
jshamlet |
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
22 |
|
|
-- THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23 |
181 |
jshamlet |
|
24 |
|
|
-- VHDL Units : Open8_pkg
|
25 |
|
|
-- Description: Contains constant definitions for the Open8 processor
|
26 |
220 |
jshamlet |
--
|
27 |
181 |
jshamlet |
-- Revision History
|
28 |
|
|
-- Author Date Change
|
29 |
|
|
------------------ -------- ---------------------------------------------------
|
30 |
|
|
-- Seth Henry 07/22/06 Design Start
|
31 |
|
|
-- Seth Henry 02/03/12 Updated generics to match current model
|
32 |
|
|
-- Seth Henry 10/29/15 Migrated type/constant definitions to this file
|
33 |
185 |
jshamlet |
-- Seth Henry 03/09/20 Created new ALU/SP opcodes for handling new RSP
|
34 |
|
|
-- Seth Henry 03/12/20 Rationalized the naming of the CPU flags to match
|
35 |
|
|
-- the assembler names. Also removed superfluous
|
36 |
|
|
-- signals in the ALU and PC records.
|
37 |
188 |
jshamlet |
-- Seth Henry 03/17/20 Added new subtype and constants for external
|
38 |
|
|
-- GP flags.
|
39 |
189 |
jshamlet |
-- Seth Henry 03/18/20 Added the ceil_log2 function, since it is used in
|
40 |
|
|
-- memory sizing calculations.
|
41 |
210 |
jshamlet |
-- Seth Henry 04/09/20 Added the I bit to the exported flags for use in
|
42 |
|
|
-- memory protection schemes.
|
43 |
181 |
jshamlet |
|
44 |
|
|
library ieee;
|
45 |
|
|
use ieee.std_logic_1164.all;
|
46 |
185 |
jshamlet |
use ieee.std_logic_arith.all;
|
47 |
181 |
jshamlet |
|
48 |
|
|
package Open8_pkg is
|
49 |
|
|
|
50 |
|
|
-------------------------------------------------------------------------------
|
51 |
|
|
-- External constants and type declarations
|
52 |
|
|
--
|
53 |
|
|
-- These subtypes can be used with external peripherals to simplify
|
54 |
|
|
-- connection to the core.
|
55 |
|
|
-------------------------------------------------------------------------------
|
56 |
|
|
|
57 |
|
|
-- These must never be changed, as the core requires them to be these static
|
58 |
|
|
-- values for proper operation. These are ONLY defined here to allow user
|
59 |
185 |
jshamlet |
-- code to dynamically configure itself to match the Open8 core.
|
60 |
181 |
jshamlet |
|
61 |
|
|
constant OPEN8_ADDR_WIDTH : integer := 16; -- DON'T EVEN CONTEMPLATE
|
62 |
|
|
constant OPEN8_DATA_WIDTH : integer := 8; -- CHANGING THESE!
|
63 |
|
|
|
64 |
|
|
subtype ADDRESS_TYPE is std_logic_vector(OPEN8_ADDR_WIDTH - 1 downto 0);
|
65 |
|
|
subtype DATA_TYPE is std_logic_vector(OPEN8_DATA_WIDTH - 1 downto 0);
|
66 |
|
|
-- Note: INTERRUPT_BUNDLE must be exactly the same width as DATA_TYPE
|
67 |
|
|
subtype INTERRUPT_BUNDLE is DATA_TYPE;
|
68 |
|
|
|
69 |
210 |
jshamlet |
subtype EXT_GP_FLAGS is std_logic_vector(4 downto 0);
|
70 |
188 |
jshamlet |
|
71 |
210 |
jshamlet |
constant EXT_ISR : integer := 0;
|
72 |
|
|
constant EXT_GP4 : integer := 1;
|
73 |
|
|
constant EXT_GP5 : integer := 2;
|
74 |
|
|
constant EXT_GP6 : integer := 3;
|
75 |
|
|
constant EXT_GP7 : integer := 4;
|
76 |
188 |
jshamlet |
|
77 |
191 |
jshamlet |
constant OPEN8_NULLBUS : DATA_TYPE := x"00";
|
78 |
|
|
|
79 |
181 |
jshamlet |
-- Component declaration
|
80 |
185 |
jshamlet |
-- (assumes a 1K RAM at 0x0000 and ROM at the top of the memory map)
|
81 |
183 |
jshamlet |
component o8_cpu is
|
82 |
181 |
jshamlet |
generic(
|
83 |
185 |
jshamlet |
Program_Start_Addr : ADDRESS_TYPE := x"8000";
|
84 |
|
|
ISR_Start_Addr : ADDRESS_TYPE := x"FFF0";
|
85 |
|
|
Stack_Start_Addr : ADDRESS_TYPE := x"03FF";
|
86 |
|
|
Allow_Stack_Address_Move : boolean := false;
|
87 |
|
|
Stack_Xfer_Flag : integer := 4;
|
88 |
|
|
Enable_Auto_Increment : boolean := false;
|
89 |
|
|
BRK_Implements_WAI : boolean := false;
|
90 |
|
|
Enable_NMI : boolean := true;
|
91 |
188 |
jshamlet |
RTI_Ignores_GP_Flags : boolean := false;
|
92 |
185 |
jshamlet |
Default_Interrupt_Mask : DATA_TYPE := x"FF";
|
93 |
|
|
Reset_Level : std_logic := '0' );
|
94 |
181 |
jshamlet |
port(
|
95 |
|
|
Clock : in std_logic;
|
96 |
|
|
Reset : in std_logic;
|
97 |
187 |
jshamlet |
CPU_Halt : in std_logic;
|
98 |
181 |
jshamlet |
Interrupts : in INTERRUPT_BUNDLE;
|
99 |
188 |
jshamlet |
GP_Flags : out EXT_GP_FLAGS;
|
100 |
181 |
jshamlet |
Address : out ADDRESS_TYPE;
|
101 |
|
|
Rd_Data : in DATA_TYPE;
|
102 |
|
|
Rd_Enable : out std_logic;
|
103 |
|
|
Wr_Data : out DATA_TYPE;
|
104 |
|
|
Wr_Enable : out std_logic );
|
105 |
|
|
end component;
|
106 |
|
|
|
107 |
189 |
jshamlet |
-- This function is used to calculate RAM parameters, but is generally
|
108 |
|
|
-- useful for making things more generic.
|
109 |
|
|
function ceil_log2 (x : in natural) return natural;
|
110 |
|
|
|
111 |
181 |
jshamlet |
-------------------------------------------------------------------------------
|
112 |
|
|
-- Internal constants and type declarations.
|
113 |
|
|
--
|
114 |
|
|
-- These are only used in the actual model, and aren't generally useful for
|
115 |
|
|
-- external application.
|
116 |
|
|
-------------------------------------------------------------------------------
|
117 |
|
|
|
118 |
|
|
subtype OPCODE_TYPE is std_logic_vector(4 downto 0);
|
119 |
|
|
subtype SUBOP_TYPE is std_logic_vector(2 downto 0);
|
120 |
|
|
|
121 |
|
|
-- All opcodes should be identical to the opcode used by the assembler
|
122 |
|
|
-- In this case, they match the original V8/ARC uRISC ISA
|
123 |
|
|
constant OP_INC : OPCODE_TYPE := "00000";
|
124 |
|
|
constant OP_ADC : OPCODE_TYPE := "00001";
|
125 |
|
|
constant OP_TX0 : OPCODE_TYPE := "00010";
|
126 |
|
|
constant OP_OR : OPCODE_TYPE := "00011";
|
127 |
|
|
constant OP_AND : OPCODE_TYPE := "00100";
|
128 |
|
|
constant OP_XOR : OPCODE_TYPE := "00101";
|
129 |
|
|
constant OP_ROL : OPCODE_TYPE := "00110";
|
130 |
|
|
constant OP_ROR : OPCODE_TYPE := "00111";
|
131 |
|
|
constant OP_DEC : OPCODE_TYPE := "01000";
|
132 |
|
|
constant OP_SBC : OPCODE_TYPE := "01001";
|
133 |
|
|
constant OP_ADD : OPCODE_TYPE := "01010";
|
134 |
|
|
constant OP_STP : OPCODE_TYPE := "01011";
|
135 |
|
|
constant OP_BTT : OPCODE_TYPE := "01100";
|
136 |
|
|
constant OP_CLP : OPCODE_TYPE := "01101";
|
137 |
|
|
constant OP_T0X : OPCODE_TYPE := "01110";
|
138 |
|
|
constant OP_CMP : OPCODE_TYPE := "01111";
|
139 |
|
|
constant OP_PSH : OPCODE_TYPE := "10000";
|
140 |
|
|
constant OP_POP : OPCODE_TYPE := "10001";
|
141 |
|
|
constant OP_BR0 : OPCODE_TYPE := "10010";
|
142 |
|
|
constant OP_BR1 : OPCODE_TYPE := "10011";
|
143 |
|
|
constant OP_DBNZ : OPCODE_TYPE := "10100"; -- USR
|
144 |
|
|
constant OP_INT : OPCODE_TYPE := "10101";
|
145 |
|
|
constant OP_MUL : OPCODE_TYPE := "10110"; -- USR2
|
146 |
|
|
constant OP_STK : OPCODE_TYPE := "10111";
|
147 |
|
|
constant OP_UPP : OPCODE_TYPE := "11000";
|
148 |
|
|
constant OP_STA : OPCODE_TYPE := "11001";
|
149 |
|
|
constant OP_STX : OPCODE_TYPE := "11010";
|
150 |
|
|
constant OP_STO : OPCODE_TYPE := "11011";
|
151 |
|
|
constant OP_LDI : OPCODE_TYPE := "11100";
|
152 |
|
|
constant OP_LDA : OPCODE_TYPE := "11101";
|
153 |
|
|
constant OP_LDX : OPCODE_TYPE := "11110";
|
154 |
|
|
constant OP_LDO : OPCODE_TYPE := "11111";
|
155 |
|
|
|
156 |
|
|
-- OP_STK uses the lower 3 bits to further refine the instruction by
|
157 |
186 |
jshamlet |
-- repurposing the source register field. These "sub opcodes" take
|
158 |
|
|
-- the place of the register select for the OP_STK opcode
|
159 |
181 |
jshamlet |
constant SOP_RSP : SUBOP_TYPE := "000";
|
160 |
|
|
constant SOP_RTS : SUBOP_TYPE := "001";
|
161 |
|
|
constant SOP_RTI : SUBOP_TYPE := "010";
|
162 |
|
|
constant SOP_BRK : SUBOP_TYPE := "011";
|
163 |
|
|
constant SOP_JMP : SUBOP_TYPE := "100";
|
164 |
|
|
constant SOP_SMSK : SUBOP_TYPE := "101";
|
165 |
|
|
constant SOP_GMSK : SUBOP_TYPE := "110";
|
166 |
|
|
constant SOP_JSR : SUBOP_TYPE := "111";
|
167 |
|
|
|
168 |
|
|
type CPU_STATES is (
|
169 |
|
|
-- Instruction fetch & Decode
|
170 |
187 |
jshamlet |
IPF_C0, IPF_C1, IPF_C2, IDC_C0,
|
171 |
181 |
jshamlet |
-- Branching
|
172 |
|
|
BRN_C1, DBNZ_C1, JMP_C1, JMP_C2,
|
173 |
|
|
-- Loads
|
174 |
185 |
jshamlet |
LDA_C1, LDA_C2, LDA_C3, LDA_C4, LDI_C1,
|
175 |
|
|
LDO_C1, LDX_C1, LDX_C2, LDX_C3, LDX_C4,
|
176 |
181 |
jshamlet |
-- Stores
|
177 |
|
|
STA_C1, STA_C2, STA_C3, STO_C1, STO_C2, STX_C1, STX_C2,
|
178 |
|
|
-- 2-cycle math
|
179 |
|
|
MUL_C1, UPP_C1,
|
180 |
|
|
-- Stack
|
181 |
|
|
PSH_C1, POP_C1, POP_C2, POP_C3, POP_C4,
|
182 |
|
|
-- Subroutines & Interrupts
|
183 |
187 |
jshamlet |
WAI_Cx, WAH_Cx, BRK_C1,
|
184 |
186 |
jshamlet |
ISR_C1, ISR_C2, ISR_C3, JSR_C1, JSR_C2,
|
185 |
187 |
jshamlet |
RTS_C1, RTS_C2, RTS_C3, RTS_C4, RTS_C5, RTI_C6
|
186 |
|
|
);
|
187 |
181 |
jshamlet |
|
188 |
|
|
type CACHE_MODES is (CACHE_IDLE, CACHE_INSTR, CACHE_OPER1, CACHE_OPER2,
|
189 |
|
|
CACHE_PREFETCH );
|
190 |
|
|
|
191 |
185 |
jshamlet |
type PC_MODES is ( PC_INCR, PC_LOAD );
|
192 |
181 |
jshamlet |
|
193 |
|
|
type PC_CTRL_TYPE is record
|
194 |
|
|
Oper : PC_MODES;
|
195 |
|
|
Offset : DATA_TYPE;
|
196 |
|
|
end record;
|
197 |
|
|
|
198 |
185 |
jshamlet |
-- These are fixed constant offsets to the program counter logic, which is
|
199 |
|
|
-- always either incrementing or loading.
|
200 |
|
|
constant PC_NEXT : DATA_TYPE := x"03";
|
201 |
|
|
constant PC_IDLE : DATA_TYPE := x"02";
|
202 |
|
|
constant PC_REV1 : DATA_TYPE := x"01";
|
203 |
|
|
constant PC_REV2 : DATA_TYPE := x"00";
|
204 |
|
|
constant PC_REV3 : DATA_TYPE := x"FF";
|
205 |
|
|
|
206 |
181 |
jshamlet |
type SP_MODES is ( SP_IDLE, SP_CLR, SP_SET, SP_POP, SP_PUSH );
|
207 |
|
|
|
208 |
|
|
type SP_CTRL_TYPE is record
|
209 |
|
|
Oper : SP_MODES;
|
210 |
|
|
end record;
|
211 |
|
|
|
212 |
|
|
type DP_MODES is ( DATA_BUS_IDLE, DATA_RD_MEM,
|
213 |
|
|
DATA_WR_REG, DATA_WR_FLAG, DATA_WR_PC );
|
214 |
|
|
|
215 |
|
|
type DATA_CTRL_TYPE is record
|
216 |
|
|
Src : DP_MODES;
|
217 |
|
|
Reg : SUBOP_TYPE;
|
218 |
|
|
end record;
|
219 |
|
|
|
220 |
182 |
jshamlet |
constant PC_LSB : SUBOP_TYPE := "000";
|
221 |
|
|
constant PC_MSB : SUBOP_TYPE := "001";
|
222 |
|
|
|
223 |
181 |
jshamlet |
type INT_CTRL_TYPE is record
|
224 |
|
|
Mask_Set : std_logic;
|
225 |
|
|
Soft_Ints : INTERRUPT_BUNDLE;
|
226 |
|
|
Incr_ISR : std_logic;
|
227 |
|
|
end record;
|
228 |
|
|
|
229 |
185 |
jshamlet |
-- Most of the ALU instructions are the same as their Opcode equivalents,
|
230 |
|
|
-- with exceptions for IDLE, UPP2, RFLG, RSP, and GMSK, which perform
|
231 |
|
|
-- internal operations not otherwise exposed by the instruction set.
|
232 |
181 |
jshamlet |
constant ALU_INC : OPCODE_TYPE := "00000"; -- x"00"
|
233 |
|
|
constant ALU_ADC : OPCODE_TYPE := "00001"; -- x"01"
|
234 |
|
|
constant ALU_TX0 : OPCODE_TYPE := "00010"; -- x"02"
|
235 |
|
|
constant ALU_OR : OPCODE_TYPE := "00011"; -- x"03"
|
236 |
|
|
constant ALU_AND : OPCODE_TYPE := "00100"; -- x"04"
|
237 |
|
|
constant ALU_XOR : OPCODE_TYPE := "00101"; -- x"05"
|
238 |
|
|
constant ALU_ROL : OPCODE_TYPE := "00110"; -- x"06"
|
239 |
|
|
constant ALU_ROR : OPCODE_TYPE := "00111"; -- x"07"
|
240 |
|
|
constant ALU_DEC : OPCODE_TYPE := "01000"; -- x"08"
|
241 |
|
|
constant ALU_SBC : OPCODE_TYPE := "01001"; -- x"09"
|
242 |
|
|
constant ALU_ADD : OPCODE_TYPE := "01010"; -- x"0A"
|
243 |
|
|
constant ALU_STP : OPCODE_TYPE := "01011"; -- x"0B"
|
244 |
|
|
constant ALU_BTT : OPCODE_TYPE := "01100"; -- x"0C"
|
245 |
|
|
constant ALU_CLP : OPCODE_TYPE := "01101"; -- x"0D"
|
246 |
|
|
constant ALU_T0X : OPCODE_TYPE := "01110"; -- x"0E"
|
247 |
|
|
constant ALU_CMP : OPCODE_TYPE := "01111"; -- x"0F"
|
248 |
|
|
constant ALU_POP : OPCODE_TYPE := "10001"; -- x"11"
|
249 |
|
|
constant ALU_MUL : OPCODE_TYPE := "10110"; -- x"16"
|
250 |
|
|
constant ALU_UPP : OPCODE_TYPE := "11000"; -- x"18"
|
251 |
|
|
constant ALU_LDI : OPCODE_TYPE := "11100"; -- x"1C"
|
252 |
|
|
|
253 |
|
|
constant ALU_IDLE : OPCODE_TYPE := "10000"; -- x"10"
|
254 |
|
|
constant ALU_UPP2 : OPCODE_TYPE := "10010"; -- x"12"
|
255 |
|
|
constant ALU_RFLG : OPCODE_TYPE := "10011"; -- x"13"
|
256 |
185 |
jshamlet |
constant ALU_RSP : OPCODE_TYPE := "10111"; -- x"17"
|
257 |
|
|
constant ALU_GMSK : OPCODE_TYPE := "11111"; -- x"1F"
|
258 |
181 |
jshamlet |
|
259 |
185 |
jshamlet |
-- These should match the assembler's definitions for the flags
|
260 |
|
|
constant PSR_Z : integer := 0;
|
261 |
|
|
constant PSR_C : integer := 1;
|
262 |
|
|
constant PSR_N : integer := 2;
|
263 |
|
|
constant PSR_I : integer := 3;
|
264 |
|
|
constant PSR_GP4 : integer := 4;
|
265 |
186 |
jshamlet |
constant PSR_GP5 : integer := 5;
|
266 |
|
|
constant PSR_GP6 : integer := 6;
|
267 |
|
|
constant PSR_GP7 : integer := 7;
|
268 |
|
|
|
269 |
|
|
type ALU_CTRL_TYPE is record
|
270 |
|
|
Oper : OPCODE_TYPE;
|
271 |
|
|
Reg : SUBOP_TYPE;
|
272 |
|
|
end record;
|
273 |
|
|
|
274 |
|
|
constant ACCUM : SUBOP_TYPE := "000";
|
275 |
|
|
|
276 |
|
|
type REGFILE_TYPE is array (0 to 7) of DATA_TYPE;
|
277 |
|
|
|
278 |
|
|
subtype FLAG_TYPE is DATA_TYPE;
|
279 |
|
|
|
280 |
|
|
end Open8_pkg;
|
281 |
|
|
|
282 |
|
|
package body Open8_pkg is
|
283 |
189 |
jshamlet |
|
284 |
|
|
-- The ceil_log2 function returns the minimum register width required to
|
285 |
|
|
-- hold the supplied integer.
|
286 |
|
|
function ceil_log2 (x : in natural) return natural is
|
287 |
|
|
variable retval : natural;
|
288 |
|
|
begin
|
289 |
|
|
retval := 1;
|
290 |
|
|
while ((2**retval) - 1) < x loop
|
291 |
|
|
retval := retval + 1;
|
292 |
|
|
end loop;
|
293 |
|
|
return retval;
|
294 |
|
|
end ceil_log2;
|
295 |
|
|
|
296 |
186 |
jshamlet |
end package body;
|