Line 1... |
Line 1... |
-- Copyright (c)2006,2011,2012,2013,2015 Jeremy Seth Henry
|
-- Copyright (c)2006,2011,2012,2013,2015,2020 Jeremy Seth Henry
|
-- All rights reserved.
|
-- All rights reserved.
|
--
|
--
|
-- Redistribution and use in source and binary forms, with or without
|
-- Redistribution and use in source and binary forms, with or without
|
-- modification, are permitted provided that the following conditions are met:
|
-- modification, are permitted provided that the following conditions are met:
|
-- * Redistributions of source code must retain the above copyright
|
-- * Redistributions of source code must retain the above copyright
|
Line 28... |
Line 28... |
------------------ -------- ---------------------------------------------------
|
------------------ -------- ---------------------------------------------------
|
-- Seth Henry 07/22/06 Design Start
|
-- Seth Henry 07/22/06 Design Start
|
-- Seth Henry 02/03/12 Updated generics to match current model
|
-- Seth Henry 02/03/12 Updated generics to match current model
|
-- Seth Henry 10/29/15 Migrated type/constant definitions to this file
|
-- Seth Henry 10/29/15 Migrated type/constant definitions to this file
|
-- Seth Henry 03/09/20 Created new ALU/SP opcodes for handling new RSP
|
-- Seth Henry 03/09/20 Created new ALU/SP opcodes for handling new RSP
|
|
-- Seth Henry 03/12/20 Rationalized the naming of the CPU flags to match
|
|
-- the assembler names. Also removed superfluous
|
|
-- signals in the ALU and PC records.
|
|
|
library ieee;
|
library ieee;
|
use ieee.std_logic_1164.all;
|
use ieee.std_logic_1164.all;
|
|
use ieee.std_logic_arith.all;
|
|
|
package Open8_pkg is
|
package Open8_pkg is
|
|
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
-- External constants and type declarations
|
-- External constants and type declarations
|
Line 43... |
Line 47... |
-- connection to the core.
|
-- connection to the core.
|
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
|
|
-- These must never be changed, as the core requires them to be these static
|
-- These must never be changed, as the core requires them to be these static
|
-- values for proper operation. These are ONLY defined here to allow user
|
-- values for proper operation. These are ONLY defined here to allow user
|
-- code to dynamically configure itself to match the Open8 core ONLY.
|
-- code to dynamically configure itself to match the Open8 core.
|
|
|
constant OPEN8_ADDR_WIDTH : integer := 16; -- DON'T EVEN CONTEMPLATE
|
constant OPEN8_ADDR_WIDTH : integer := 16; -- DON'T EVEN CONTEMPLATE
|
constant OPEN8_DATA_WIDTH : integer := 8; -- CHANGING THESE!
|
constant OPEN8_DATA_WIDTH : integer := 8; -- CHANGING THESE!
|
|
|
subtype ADDRESS_TYPE is std_logic_vector(OPEN8_ADDR_WIDTH - 1 downto 0);
|
subtype ADDRESS_TYPE is std_logic_vector(OPEN8_ADDR_WIDTH - 1 downto 0);
|
subtype DATA_TYPE is std_logic_vector(OPEN8_DATA_WIDTH - 1 downto 0);
|
subtype DATA_TYPE is std_logic_vector(OPEN8_DATA_WIDTH - 1 downto 0);
|
-- Note: INTERRUPT_BUNDLE must be exactly the same width as DATA_TYPE
|
-- Note: INTERRUPT_BUNDLE must be exactly the same width as DATA_TYPE
|
subtype INTERRUPT_BUNDLE is DATA_TYPE;
|
subtype INTERRUPT_BUNDLE is DATA_TYPE;
|
|
|
-- Component declaration
|
-- Component declaration
|
-- (assumes a 1K RAM at 0x0000 and ROM at the end of the memory map)
|
-- (assumes a 1K RAM at 0x0000 and ROM at the top of the memory map)
|
component o8_cpu is
|
component o8_cpu is
|
generic(
|
generic(
|
Program_Start_Addr : ADDRESS_TYPE := x"8000"; -- Initial PC location
|
Program_Start_Addr : ADDRESS_TYPE := x"8000";
|
ISR_Start_Addr : ADDRESS_TYPE := x"FFF0"; -- Bottom of ISR vec's
|
ISR_Start_Addr : ADDRESS_TYPE := x"FFF0";
|
Stack_Start_Addr : ADDRESS_TYPE := x"03FF"; -- Top of Stack
|
Stack_Start_Addr : ADDRESS_TYPE := x"03FF";
|
Allow_Stack_Address_Move : boolean := false; -- Use Normal v8 RSP
|
Allow_Stack_Address_Move : boolean := false;
|
Stack_Xfer_Flag : integer := 4; -- If enabled, GP1 alters RSP
|
Stack_Xfer_Flag : integer := 4;
|
Enable_Auto_Increment : boolean := false; -- Modify indexed instr
|
Enable_Auto_Increment : boolean := false;
|
BRK_Implements_WAI : boolean := false; -- BRK -> Wait for Int
|
BRK_Implements_WAI : boolean := false;
|
Enable_NMI : boolean := true; -- Force INTR0 enabled
|
Enable_NMI : boolean := true;
|
Default_Interrupt_Mask : DATA_TYPE := x"FF"; -- Enable all Ints
|
Default_Interrupt_Mask : DATA_TYPE := x"FF";
|
Reset_Level : std_logic := '0' ); -- Active reset level
|
Reset_Level : std_logic := '0' );
|
port(
|
port(
|
Clock : in std_logic;
|
Clock : in std_logic;
|
Reset : in std_logic;
|
Reset : in std_logic;
|
Interrupts : in INTERRUPT_BUNDLE;
|
Interrupts : in INTERRUPT_BUNDLE;
|
Address : out ADDRESS_TYPE;
|
Address : out ADDRESS_TYPE;
|
Line 141... |
Line 145... |
-- Instruction fetch & Decode
|
-- Instruction fetch & Decode
|
PIPE_FILL_0, PIPE_FILL_1, PIPE_FILL_2, INSTR_DECODE,
|
PIPE_FILL_0, PIPE_FILL_1, PIPE_FILL_2, INSTR_DECODE,
|
-- Branching
|
-- Branching
|
BRN_C1, DBNZ_C1, JMP_C1, JMP_C2,
|
BRN_C1, DBNZ_C1, JMP_C1, JMP_C2,
|
-- Loads
|
-- Loads
|
LDA_C1, LDA_C2, LDA_C3, LDA_C4, LDI_C1, LDO_C1, LDX_C1, LDX_C2, LDX_C3, LDX_C4,
|
LDA_C1, LDA_C2, LDA_C3, LDA_C4, LDI_C1,
|
|
LDO_C1, LDX_C1, LDX_C2, LDX_C3, LDX_C4,
|
-- Stores
|
-- Stores
|
STA_C1, STA_C2, STA_C3, STO_C1, STO_C2, STX_C1, STX_C2,
|
STA_C1, STA_C2, STA_C3, STO_C1, STO_C2, STX_C1, STX_C2,
|
-- 2-cycle math
|
-- 2-cycle math
|
MUL_C1, UPP_C1,
|
MUL_C1, UPP_C1,
|
-- Stack
|
-- Stack
|
Line 157... |
Line 162... |
BRK_C1 );
|
BRK_C1 );
|
|
|
type CACHE_MODES is (CACHE_IDLE, CACHE_INSTR, CACHE_OPER1, CACHE_OPER2,
|
type CACHE_MODES is (CACHE_IDLE, CACHE_INSTR, CACHE_OPER1, CACHE_OPER2,
|
CACHE_PREFETCH );
|
CACHE_PREFETCH );
|
|
|
type PC_MODES is ( PC_IDLE, PC_REV1, PC_REV2, PC_INCR, PC_LOAD );
|
type PC_MODES is ( PC_INCR, PC_LOAD );
|
|
|
type PC_CTRL_TYPE is record
|
type PC_CTRL_TYPE is record
|
Oper : PC_MODES;
|
Oper : PC_MODES;
|
Offset : DATA_TYPE;
|
Offset : DATA_TYPE;
|
Addr : ADDRESS_TYPE;
|
|
end record;
|
end record;
|
|
|
|
-- These are fixed constant offsets to the program counter logic, which is
|
|
-- always either incrementing or loading.
|
|
constant PC_NEXT : DATA_TYPE := x"03";
|
|
constant PC_IDLE : DATA_TYPE := x"02";
|
|
constant PC_REV1 : DATA_TYPE := x"01";
|
|
constant PC_REV2 : DATA_TYPE := x"00";
|
|
constant PC_REV3 : DATA_TYPE := x"FF";
|
|
|
type SP_MODES is ( SP_IDLE, SP_CLR, SP_SET, SP_POP, SP_PUSH );
|
type SP_MODES is ( SP_IDLE, SP_CLR, SP_SET, SP_POP, SP_PUSH );
|
|
|
type SP_CTRL_TYPE is record
|
type SP_CTRL_TYPE is record
|
Oper : SP_MODES;
|
Oper : SP_MODES;
|
end record;
|
end record;
|
Line 188... |
Line 200... |
Mask_Set : std_logic;
|
Mask_Set : std_logic;
|
Soft_Ints : INTERRUPT_BUNDLE;
|
Soft_Ints : INTERRUPT_BUNDLE;
|
Incr_ISR : std_logic;
|
Incr_ISR : std_logic;
|
end record;
|
end record;
|
|
|
-- Most of the ALU instructions are the same as their Opcode equivalents with
|
-- Most of the ALU instructions are the same as their Opcode equivalents,
|
-- three exceptions (for IDLE, UPP2, and MUL2)
|
-- with exceptions for IDLE, UPP2, RFLG, RSP, and GMSK, which perform
|
|
-- internal operations not otherwise exposed by the instruction set.
|
constant ALU_INC : OPCODE_TYPE := "00000"; -- x"00"
|
constant ALU_INC : OPCODE_TYPE := "00000"; -- x"00"
|
constant ALU_ADC : OPCODE_TYPE := "00001"; -- x"01"
|
constant ALU_ADC : OPCODE_TYPE := "00001"; -- x"01"
|
constant ALU_TX0 : OPCODE_TYPE := "00010"; -- x"02"
|
constant ALU_TX0 : OPCODE_TYPE := "00010"; -- x"02"
|
constant ALU_OR : OPCODE_TYPE := "00011"; -- x"03"
|
constant ALU_OR : OPCODE_TYPE := "00011"; -- x"03"
|
constant ALU_AND : OPCODE_TYPE := "00100"; -- x"04"
|
constant ALU_AND : OPCODE_TYPE := "00100"; -- x"04"
|
Line 214... |
Line 227... |
constant ALU_LDI : OPCODE_TYPE := "11100"; -- x"1C"
|
constant ALU_LDI : OPCODE_TYPE := "11100"; -- x"1C"
|
|
|
constant ALU_IDLE : OPCODE_TYPE := "10000"; -- x"10"
|
constant ALU_IDLE : OPCODE_TYPE := "10000"; -- x"10"
|
constant ALU_UPP2 : OPCODE_TYPE := "10010"; -- x"12"
|
constant ALU_UPP2 : OPCODE_TYPE := "10010"; -- x"12"
|
constant ALU_RFLG : OPCODE_TYPE := "10011"; -- x"13"
|
constant ALU_RFLG : OPCODE_TYPE := "10011"; -- x"13"
|
constant ALU_TSX : OPCODE_TYPE := "10111"; -- x"17"
|
constant ALU_RSP : OPCODE_TYPE := "10111"; -- x"17"
|
|
constant ALU_GMSK : OPCODE_TYPE := "11111"; -- x"1F"
|
constant FL_ZERO : integer := 0;
|
|
constant FL_CARRY : integer := 1;
|
|
constant FL_NEG : integer := 2;
|
|
constant FL_INT_EN : integer := 3;
|
|
constant FL_GP1 : integer := 4;
|
|
constant FL_GP2 : integer := 5;
|
|
constant FL_GP3 : integer := 6;
|
|
constant FL_GP4 : integer := 7;
|
|
|
|
type ALU_CTRL_TYPE is record
|
|
Oper : OPCODE_TYPE;
|
|
Reg : SUBOP_TYPE;
|
|
Data : DATA_TYPE;
|
|
end record;
|
|
|
|
constant ACCUM : SUBOP_TYPE := "000";
|
|
constant INT_FLAG : SUBOP_TYPE := "011";
|
|
|
|
type REGFILE_TYPE is array (0 to 7) of DATA_TYPE;
|
|
|
|
subtype FLAG_TYPE is DATA_TYPE;
|
|
|
|
end Open8_pkg;
|
|
|
|
package body Open8_pkg is
|
|
end package body;
|
|
|
|
No newline at end of file
|
No newline at end of file
|
|
-- These should match the assembler's definitions for the flags
|
|
constant PSR_Z : integer := 0;
|
|
constant PSR_C : integer := 1;
|
|
constant PSR_N : integer := 2;
|
|
constant PSR_I : integer := 3;
|
|
constant PSR_GP4 : integer := 4;
|
|
constant PSR_GP5 :
|
No newline at end of file
|
No newline at end of file
|