| 1 |
169 |
jshamlet |
-- Copyright (c)2006,2011,2012,2013,2015 Jeremy Seth Henry
|
| 2 |
151 |
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 |
|
|
-- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
| 22 |
|
|
-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 23 |
|
|
|
| 24 |
|
|
-- VHDL Units : Open8_pkg
|
| 25 |
|
|
-- Description: Contains constant definitions for the Open8 processor
|
| 26 |
|
|
-- Revision History
|
| 27 |
|
|
-- Author Date Change
|
| 28 |
|
|
------------------ -------- ---------------------------------------------------
|
| 29 |
|
|
-- Seth Henry 07/22/06 Design Start
|
| 30 |
169 |
jshamlet |
-- Seth Henry 02/03/12 Updated generics to match current model
|
| 31 |
|
|
-- Seth Henry 10/29/15 Migrated type/constant definitions to this file
|
| 32 |
151 |
jshamlet |
|
| 33 |
|
|
library ieee;
|
| 34 |
|
|
use ieee.std_logic_1164.all;
|
| 35 |
|
|
|
| 36 |
|
|
package Open8_pkg is
|
| 37 |
|
|
|
| 38 |
169 |
jshamlet |
-------------------------------------------------------------------------------
|
| 39 |
|
|
-- External constants and type declarations
|
| 40 |
|
|
--
|
| 41 |
|
|
-- These subtypes can be used with external peripherals to simplify
|
| 42 |
172 |
jshamlet |
-- connection to the core.
|
| 43 |
169 |
jshamlet |
-------------------------------------------------------------------------------
|
| 44 |
|
|
|
| 45 |
|
|
-- These must never be changed, as the core requires them to be these static
|
| 46 |
|
|
-- values for proper operation. These are ONLY defined here to allow user
|
| 47 |
|
|
-- code to dynamically configure itself to match the Open8 core ONLY.
|
| 48 |
|
|
|
| 49 |
|
|
constant OPEN8_ADDR_WIDTH : integer := 16; -- DON'T EVEN CONTEMPLATE
|
| 50 |
|
|
constant OPEN8_DATA_WIDTH : integer := 8; -- CHANGING THESE!
|
| 51 |
|
|
|
| 52 |
|
|
subtype ADDRESS_TYPE is std_logic_vector(OPEN8_ADDR_WIDTH - 1 downto 0);
|
| 53 |
|
|
subtype DATA_TYPE is std_logic_vector(OPEN8_DATA_WIDTH - 1 downto 0);
|
| 54 |
151 |
jshamlet |
-- Note: INTERRUPT_BUNDLE must be exactly the same width as DATA_TYPE
|
| 55 |
|
|
subtype INTERRUPT_BUNDLE is DATA_TYPE;
|
| 56 |
169 |
jshamlet |
|
| 57 |
151 |
jshamlet |
-- Component declaration
|
| 58 |
169 |
jshamlet |
-- (assumes a 1K RAM at 0x0000 and ROM at the end of the memory map)
|
| 59 |
151 |
jshamlet |
component Open8_CPU is
|
| 60 |
|
|
generic(
|
| 61 |
169 |
jshamlet |
Program_Start_Addr : ADDRESS_TYPE := x"8000"; -- Initial PC location
|
| 62 |
|
|
ISR_Start_Addr : ADDRESS_TYPE := x"FFF0"; -- Bottom of ISR vec's
|
| 63 |
|
|
Stack_Start_Addr : ADDRESS_TYPE := x"03FF"; -- Top of Stack
|
| 64 |
|
|
Allow_Stack_Address_Move : boolean := false; -- Use Normal v8 RSP
|
| 65 |
|
|
Enable_Auto_Increment : boolean := false; -- Modify indexed instr
|
| 66 |
|
|
BRK_Implements_WAI : boolean := false; -- BRK -> Wait for Int
|
| 67 |
|
|
Enable_NMI : boolean := true; -- Force INTR0 enabled
|
| 68 |
|
|
Default_Interrupt_Mask : DATA_TYPE := x"FF"; -- Enable all Ints
|
| 69 |
|
|
Reset_Level : std_logic := '0' ); -- Active reset level
|
| 70 |
151 |
jshamlet |
port(
|
| 71 |
|
|
Clock : in std_logic;
|
| 72 |
|
|
Reset : in std_logic;
|
| 73 |
|
|
Interrupts : in INTERRUPT_BUNDLE;
|
| 74 |
|
|
Address : out ADDRESS_TYPE;
|
| 75 |
|
|
Rd_Data : in DATA_TYPE;
|
| 76 |
|
|
Rd_Enable : out std_logic;
|
| 77 |
|
|
Wr_Data : out DATA_TYPE;
|
| 78 |
|
|
Wr_Enable : out std_logic );
|
| 79 |
|
|
end component;
|
| 80 |
|
|
|
| 81 |
169 |
jshamlet |
-------------------------------------------------------------------------------
|
| 82 |
172 |
jshamlet |
-- Internal constants and type declarations.
|
| 83 |
169 |
jshamlet |
--
|
| 84 |
|
|
-- These are only used in the actual model, and aren't generally useful for
|
| 85 |
|
|
-- external application.
|
| 86 |
|
|
-------------------------------------------------------------------------------
|
| 87 |
|
|
|
| 88 |
|
|
subtype OPCODE_TYPE is std_logic_vector(4 downto 0);
|
| 89 |
|
|
subtype SUBOP_TYPE is std_logic_vector(2 downto 0);
|
| 90 |
|
|
|
| 91 |
|
|
-- All opcodes should be identical to the opcode used by the assembler
|
| 92 |
|
|
-- In this case, they match the original V8/ARC uRISC ISA
|
| 93 |
|
|
constant OP_INC : OPCODE_TYPE := "00000";
|
| 94 |
|
|
constant OP_ADC : OPCODE_TYPE := "00001";
|
| 95 |
|
|
constant OP_TX0 : OPCODE_TYPE := "00010";
|
| 96 |
|
|
constant OP_OR : OPCODE_TYPE := "00011";
|
| 97 |
|
|
constant OP_AND : OPCODE_TYPE := "00100";
|
| 98 |
|
|
constant OP_XOR : OPCODE_TYPE := "00101";
|
| 99 |
|
|
constant OP_ROL : OPCODE_TYPE := "00110";
|
| 100 |
|
|
constant OP_ROR : OPCODE_TYPE := "00111";
|
| 101 |
|
|
constant OP_DEC : OPCODE_TYPE := "01000";
|
| 102 |
|
|
constant OP_SBC : OPCODE_TYPE := "01001";
|
| 103 |
|
|
constant OP_ADD : OPCODE_TYPE := "01010";
|
| 104 |
|
|
constant OP_STP : OPCODE_TYPE := "01011";
|
| 105 |
|
|
constant OP_BTT : OPCODE_TYPE := "01100";
|
| 106 |
|
|
constant OP_CLP : OPCODE_TYPE := "01101";
|
| 107 |
|
|
constant OP_T0X : OPCODE_TYPE := "01110";
|
| 108 |
|
|
constant OP_CMP : OPCODE_TYPE := "01111";
|
| 109 |
|
|
constant OP_PSH : OPCODE_TYPE := "10000";
|
| 110 |
|
|
constant OP_POP : OPCODE_TYPE := "10001";
|
| 111 |
|
|
constant OP_BR0 : OPCODE_TYPE := "10010";
|
| 112 |
|
|
constant OP_BR1 : OPCODE_TYPE := "10011";
|
| 113 |
|
|
constant OP_DBNZ : OPCODE_TYPE := "10100"; -- USR
|
| 114 |
|
|
constant OP_INT : OPCODE_TYPE := "10101";
|
| 115 |
|
|
constant OP_MUL : OPCODE_TYPE := "10110"; -- USR2
|
| 116 |
|
|
constant OP_STK : OPCODE_TYPE := "10111";
|
| 117 |
|
|
constant OP_UPP : OPCODE_TYPE := "11000";
|
| 118 |
|
|
constant OP_STA : OPCODE_TYPE := "11001";
|
| 119 |
|
|
constant OP_STX : OPCODE_TYPE := "11010";
|
| 120 |
|
|
constant OP_STO : OPCODE_TYPE := "11011";
|
| 121 |
|
|
constant OP_LDI : OPCODE_TYPE := "11100";
|
| 122 |
|
|
constant OP_LDA : OPCODE_TYPE := "11101";
|
| 123 |
|
|
constant OP_LDX : OPCODE_TYPE := "11110";
|
| 124 |
|
|
constant OP_LDO : OPCODE_TYPE := "11111";
|
| 125 |
|
|
|
| 126 |
|
|
-- OP_STK uses the lower 3 bits to further refine the instruction by
|
| 127 |
|
|
-- repurposing the source register field. These "sub opcodes" are
|
| 128 |
|
|
-- take the place of the register select for the OP_STK opcode
|
| 129 |
|
|
constant SOP_RSP : SUBOP_TYPE := "000";
|
| 130 |
|
|
constant SOP_RTS : SUBOP_TYPE := "001";
|
| 131 |
|
|
constant SOP_RTI : SUBOP_TYPE := "010";
|
| 132 |
|
|
constant SOP_BRK : SUBOP_TYPE := "011";
|
| 133 |
|
|
constant SOP_JMP : SUBOP_TYPE := "100";
|
| 134 |
|
|
constant SOP_SMSK : SUBOP_TYPE := "101";
|
| 135 |
|
|
constant SOP_GMSK : SUBOP_TYPE := "110";
|
| 136 |
|
|
constant SOP_JSR : SUBOP_TYPE := "111";
|
| 137 |
|
|
|
| 138 |
|
|
type CPU_STATES is (
|
| 139 |
|
|
-- Instruction fetch & Decode
|
| 140 |
|
|
PIPE_FILL_0, PIPE_FILL_1, PIPE_FILL_2, INSTR_DECODE,
|
| 141 |
|
|
-- Branching
|
| 142 |
|
|
BRN_C1, DBNZ_C1, JMP_C1, JMP_C2,
|
| 143 |
|
|
-- Loads
|
| 144 |
|
|
LDA_C1, LDA_C2, LDA_C3, LDA_C4, LDI_C1, LDO_C1, LDX_C1, LDX_C2, LDX_C3,
|
| 145 |
|
|
-- Stores
|
| 146 |
|
|
STA_C1, STA_C2, STA_C3, STO_C1, STO_C2, STX_C1, STX_C2,
|
| 147 |
|
|
-- 2-cycle math
|
| 148 |
|
|
MUL_C1, UPP_C1,
|
| 149 |
|
|
-- Stack
|
| 150 |
|
|
PSH_C1, POP_C1, POP_C2, POP_C3, POP_C4,
|
| 151 |
|
|
-- Subroutines & Interrupts
|
| 152 |
|
|
WAIT_FOR_INT, ISR_C1, ISR_C2, ISR_C3, JSR_C1, JSR_C2,
|
| 153 |
|
|
RTS_C1, RTS_C2, RTS_C3, RTS_C4, RTS_C5, RTI_C6,
|
| 154 |
|
|
-- Debugging
|
| 155 |
|
|
BRK_C1 );
|
| 156 |
|
|
|
| 157 |
|
|
type CACHE_MODES is (CACHE_IDLE, CACHE_INSTR, CACHE_OPER1, CACHE_OPER2,
|
| 158 |
|
|
CACHE_PREFETCH );
|
| 159 |
|
|
|
| 160 |
|
|
type PC_MODES is ( PC_IDLE, PC_REV1, PC_REV2, PC_INCR, PC_LOAD );
|
| 161 |
|
|
|
| 162 |
|
|
type PC_CTRL_TYPE is record
|
| 163 |
|
|
Oper : PC_MODES;
|
| 164 |
|
|
Offset : DATA_TYPE;
|
| 165 |
|
|
Addr : ADDRESS_TYPE;
|
| 166 |
|
|
end record;
|
| 167 |
|
|
|
| 168 |
|
|
type SP_MODES is ( SP_IDLE, SP_RSET, SP_POP, SP_PUSH );
|
| 169 |
|
|
|
| 170 |
|
|
type SP_CTRL_TYPE is record
|
| 171 |
|
|
Oper : SP_MODES;
|
| 172 |
|
|
Addr : ADDRESS_TYPE;
|
| 173 |
|
|
end record;
|
| 174 |
|
|
|
| 175 |
|
|
type DP_MODES is ( DATA_BUS_IDLE, DATA_RD_MEM,
|
| 176 |
|
|
DATA_WR_REG, DATA_WR_FLAG, DATA_WR_PC );
|
| 177 |
|
|
|
| 178 |
|
|
type DATA_CTRL_TYPE is record
|
| 179 |
|
|
Src : DP_MODES;
|
| 180 |
|
|
Reg : SUBOP_TYPE;
|
| 181 |
|
|
end record;
|
| 182 |
|
|
|
| 183 |
|
|
type INT_CTRL_TYPE is record
|
| 184 |
|
|
Mask_Set : std_logic;
|
| 185 |
|
|
Soft_Ints : INTERRUPT_BUNDLE;
|
| 186 |
|
|
Incr_ISR : std_logic;
|
| 187 |
|
|
end record;
|
| 188 |
|
|
|
| 189 |
|
|
-- Most of the ALU instructions are the same as their Opcode equivalents with
|
| 190 |
|
|
-- three exceptions (for IDLE, UPP2, and MUL2)
|
| 191 |
|
|
constant ALU_INC : OPCODE_TYPE := "00000"; -- x"00"
|
| 192 |
|
|
constant ALU_ADC : OPCODE_TYPE := "00001"; -- x"01"
|
| 193 |
|
|
constant ALU_TX0 : OPCODE_TYPE := "00010"; -- x"02"
|
| 194 |
|
|
constant ALU_OR : OPCODE_TYPE := "00011"; -- x"03"
|
| 195 |
|
|
constant ALU_AND : OPCODE_TYPE := "00100"; -- x"04"
|
| 196 |
|
|
constant ALU_XOR : OPCODE_TYPE := "00101"; -- x"05"
|
| 197 |
|
|
constant ALU_ROL : OPCODE_TYPE := "00110"; -- x"06"
|
| 198 |
|
|
constant ALU_ROR : OPCODE_TYPE := "00111"; -- x"07"
|
| 199 |
|
|
constant ALU_DEC : OPCODE_TYPE := "01000"; -- x"08"
|
| 200 |
|
|
constant ALU_SBC : OPCODE_TYPE := "01001"; -- x"09"
|
| 201 |
|
|
constant ALU_ADD : OPCODE_TYPE := "01010"; -- x"0A"
|
| 202 |
|
|
constant ALU_STP : OPCODE_TYPE := "01011"; -- x"0B"
|
| 203 |
|
|
constant ALU_BTT : OPCODE_TYPE := "01100"; -- x"0C"
|
| 204 |
|
|
constant ALU_CLP : OPCODE_TYPE := "01101"; -- x"0D"
|
| 205 |
|
|
constant ALU_T0X : OPCODE_TYPE := "01110"; -- x"0E"
|
| 206 |
|
|
constant ALU_CMP : OPCODE_TYPE := "01111"; -- x"0F"
|
| 207 |
|
|
constant ALU_POP : OPCODE_TYPE := "10001"; -- x"11"
|
| 208 |
|
|
constant ALU_MUL : OPCODE_TYPE := "10110"; -- x"16"
|
| 209 |
|
|
constant ALU_UPP : OPCODE_TYPE := "11000"; -- x"18"
|
| 210 |
|
|
constant ALU_LDI : OPCODE_TYPE := "11100"; -- x"1C"
|
| 211 |
|
|
constant ALU_LDX : OPCODE_TYPE := "11110"; -- x"1E"
|
| 212 |
|
|
|
| 213 |
|
|
constant ALU_IDLE : OPCODE_TYPE := "10000"; -- x"10"
|
| 214 |
|
|
constant ALU_UPP2 : OPCODE_TYPE := "10010"; -- x"12"
|
| 215 |
|
|
constant ALU_RFLG : OPCODE_TYPE := "10011"; -- x"13"
|
| 216 |
|
|
|
| 217 |
|
|
constant FL_ZERO : integer := 0;
|
| 218 |
|
|
constant FL_CARRY : integer := 1;
|
| 219 |
|
|
constant FL_NEG : integer := 2;
|
| 220 |
|
|
constant FL_INT_EN : integer := 3;
|
| 221 |
|
|
constant FL_GP1 : integer := 4;
|
| 222 |
|
|
constant FL_GP2 : integer := 5;
|
| 223 |
|
|
constant FL_GP3 : integer := 6;
|
| 224 |
|
|
constant FL_GP4 : integer := 7;
|
| 225 |
|
|
|
| 226 |
|
|
type ALU_CTRL_TYPE is record
|
| 227 |
|
|
Oper : OPCODE_TYPE;
|
| 228 |
|
|
Reg : SUBOP_TYPE;
|
| 229 |
|
|
Data : DATA_TYPE;
|
| 230 |
|
|
end record;
|
| 231 |
|
|
|
| 232 |
|
|
constant ACCUM : SUBOP_TYPE := "000";
|
| 233 |
|
|
constant INT_FLAG : SUBOP_TYPE := "011";
|
| 234 |
|
|
|
| 235 |
|
|
type REGFILE_TYPE is array (0 to 7) of DATA_TYPE;
|
| 236 |
|
|
|
| 237 |
|
|
subtype FLAG_TYPE is DATA_TYPE;
|
| 238 |
|
|
|
| 239 |
151 |
jshamlet |
end Open8_pkg;
|
| 240 |
|
|
|
| 241 |
|
|
package body Open8_pkg is
|
| 242 |
|
|
end package body;
|