| 1 |
4 |
atypic |
library ieee;
|
| 2 |
|
|
use ieee.std_logic_1164.all;
|
| 3 |
|
|
|
| 4 |
|
|
package leval2_package is
|
| 5 |
|
|
constant SCRATCH_MEM_INIT : string := "scratch";
|
| 6 |
|
|
constant INSTR_MEM_INIT : string := "instrmem";
|
| 7 |
|
|
|
| 8 |
|
|
constant WORD_BITS : integer := 32;
|
| 9 |
|
|
constant ADDR_BITS : integer := 26;
|
| 10 |
|
|
constant INSTR_MEM_SIZE : integer := 4096;
|
| 11 |
|
|
constant REGS_SIZE : integer := 1024;
|
| 12 |
|
|
constant REGS_ADDR_BITS : integer := 10;
|
| 13 |
|
|
constant MC_ADDR_BITS : integer := 13;
|
| 14 |
|
|
constant STATUS_REG_BITS : integer := 8;
|
| 15 |
|
|
constant MC_INSTR_BITS : integer := 48;
|
| 16 |
|
|
|
| 17 |
|
|
constant BUS_BITS : integer := 32;
|
| 18 |
|
|
|
| 19 |
|
|
constant INSTR_OPCODE_BITS : integer := 6;
|
| 20 |
|
|
constant INSTR_TYPE_BITS : integer := 5;
|
| 21 |
|
|
constant INSTR_REG1_START : integer := 38;
|
| 22 |
|
|
constant INSTR_REG1_END : integer := 29;
|
| 23 |
|
|
constant INSTR_REG2_START : integer := 27;
|
| 24 |
|
|
constant INSTR_REG2_END : integer := 18;
|
| 25 |
|
|
constant INSTR_REG3_START : integer := 17;
|
| 26 |
|
|
constant INSTR_IMM_START : integer := 17;
|
| 27 |
|
|
constant INSTR_REG3_END : integer := 7;
|
| 28 |
|
|
constant INSTR_REG1_INDIR : integer := 39;
|
| 29 |
|
|
constant INSTR_REG2_INDIR : integer := 28;
|
| 30 |
|
|
|
| 31 |
|
|
constant INSTR_OPCODE_START : integer := 45;
|
| 32 |
|
|
constant INSTR_OPCODE_END : integer := 40;
|
| 33 |
|
|
|
| 34 |
|
|
-- Status flags
|
| 35 |
|
|
constant ZERO : integer := 3;
|
| 36 |
|
|
constant TYP : integer := 4;
|
| 37 |
|
|
constant OVERFLOW : integer := 0;
|
| 38 |
|
|
constant NEG : integer := 2;
|
| 39 |
|
|
constant IO : integer := 5;
|
| 40 |
|
|
|
| 41 |
|
|
-- ALU operations
|
| 42 |
|
|
constant ALU_PASS : std_logic_vector(5 downto 0) := "000000";
|
| 43 |
|
|
constant ALU_ADD : std_logic_vector(5 downto 0) := "000001";
|
| 44 |
|
|
constant ALU_GET_TYPE : std_logic_vector(5 downto 0) := "000010";
|
| 45 |
|
|
constant ALU_SET_TYPE : std_logic_vector(5 downto 0) := "000011";
|
| 46 |
|
|
constant ALU_SET_DATUM : std_logic_vector(5 downto 0) := "000100";
|
| 47 |
|
|
constant ALU_GET_DATUM : std_logic_vector(5 downto 0) := "000101";
|
| 48 |
|
|
constant ALU_SET_GC : std_logic_vector(5 downto 0) := "001110";
|
| 49 |
|
|
constant ALU_GET_GC : std_logic_vector(5 downto 0) := "000110";
|
| 50 |
|
|
constant ALU_SUB : std_logic_vector(5 downto 0) := "000111";
|
| 51 |
|
|
constant ALU_CMP_TYPE : std_logic_vector(5 downto 0) := "001000";
|
| 52 |
|
|
constant ALU_AND : std_logic_vector(5 downto 0) := "001001";
|
| 53 |
|
|
constant ALU_OR : std_logic_vector(5 downto 0) := "001010";
|
| 54 |
|
|
constant ALU_XOR : std_logic_vector(5 downto 0) := "001011";
|
| 55 |
|
|
constant ALU_MUL : std_logic_vector(5 downto 0) := "001100";
|
| 56 |
|
|
constant ALU_DIV : std_logic_vector(5 downto 0) := "001101";
|
| 57 |
|
|
constant ALU_MOD : std_logic_vector(5 downto 0) := "001111";
|
| 58 |
|
|
constant ALU_SL : std_logic_Vector(5 downto 0) := "010000";
|
| 59 |
|
|
constant ALU_SR : std_logic_Vector(5 downto 0) := "010001";
|
| 60 |
|
|
constant ALU_SETLED : std_logic_Vector(5 downto 0) := "010010";
|
| 61 |
|
|
|
| 62 |
|
|
|
| 63 |
|
|
-- opcodes
|
| 64 |
|
|
-- compare operations
|
| 65 |
|
|
constant ALU_CMP_DATUM : std_logic_vector(5 downto 0) := "010111";
|
| 66 |
|
|
constant ALU_CMP_GC : std_logic_vector(5 downto 0) := "011111";
|
| 67 |
|
|
constant ALU_CMP : std_logic_vector(5 downto 0) := "100000";
|
| 68 |
|
|
constant ALU_CMP_TYPE_IMM : std_logic_vector(5 downto 0) := "010010";
|
| 69 |
|
|
constant ALU_CMP_DATUM_IMM : std_logic_vector(5 downto 0) := "010011";
|
| 70 |
|
|
constant ALU_CMP_GC_IMM : std_logic_vector(5 downto 0) := "010100";
|
| 71 |
|
|
-- set operation
|
| 72 |
|
|
constant ALU_CPY : std_logic_vector(5 downto 0) := "010101";
|
| 73 |
|
|
|
| 74 |
|
|
|
| 75 |
|
|
-- system operations
|
| 76 |
|
|
constant NOP : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "000000";
|
| 77 |
|
|
constant HALT : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "000001";
|
| 78 |
|
|
-- integer instructions
|
| 79 |
|
|
constant ADD : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "000010";
|
| 80 |
|
|
constant SUBB : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "000011";
|
| 81 |
|
|
constant MUL : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "000100";
|
| 82 |
|
|
constant DIV : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "000101";
|
| 83 |
|
|
constant MODULO : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "001011";
|
| 84 |
|
|
constant SHIFT_L : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "001010";
|
| 85 |
|
|
constant SHIFT_R : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "001100";
|
| 86 |
|
|
-- logical instructions
|
| 87 |
|
|
constant LAND : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "000110";
|
| 88 |
|
|
constant LOR : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "000111";
|
| 89 |
|
|
constant LXOR : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "001000";
|
| 90 |
|
|
-- memory instructions
|
| 91 |
|
|
constant LOAD : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "010000";
|
| 92 |
|
|
constant STORE : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "010001";
|
| 93 |
|
|
-- branch instructions
|
| 94 |
|
|
constant BIDX : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "010110";
|
| 95 |
|
|
-- data manipulation
|
| 96 |
|
|
constant GET_TYPE : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "100000";
|
| 97 |
|
|
constant SET_TYPE : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "100001";
|
| 98 |
|
|
constant SET_DATUM : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "100011";
|
| 99 |
|
|
constant GET_GC : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "100101";
|
| 100 |
|
|
constant SET_GC : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "100110";
|
| 101 |
|
|
constant CPY : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "101000";
|
| 102 |
|
|
constant SET_TYPE_IMM : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "100010";
|
| 103 |
|
|
constant SET_DATUM_IMM: std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "100100";
|
| 104 |
|
|
constant SET_GC_IMM : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "100111";
|
| 105 |
|
|
-- compare functions
|
| 106 |
|
|
constant CMP_TYPE : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "101001";
|
| 107 |
|
|
constant CMP_TYPE_IMM: std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "101010";
|
| 108 |
|
|
constant CMP_DATUM : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "101011";
|
| 109 |
|
|
constant CMP_DATUM_IMM: std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "101100";
|
| 110 |
|
|
constant CMP_GC : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "101101";
|
| 111 |
|
|
constant CMP_GC_IMM : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "101110";
|
| 112 |
|
|
constant CMP : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "101111";
|
| 113 |
|
|
constant SETLED : std_logic_vector(INSTR_OPCODE_BITS-1 downto 0) := "111111";
|
| 114 |
|
|
-- status masks
|
| 115 |
|
|
constant SM_INT : std_logic_vector(STATUS_REG_BITS-1 downto 0) := "11110110";
|
| 116 |
|
|
constant SM_LOG : std_logic_vector(STATUS_REG_BITS-1 downto 0) := "11000110";
|
| 117 |
|
|
constant SM_FPO : std_logic_vector(STATUS_REG_BITS-1 downto 0) := "11111110";
|
| 118 |
|
|
constant SM_SYS : std_logic_vector(STATUS_REG_BITS-1 downto 0) := "00000000";
|
| 119 |
|
|
constant SM_MEM : std_logic_vector(STATUS_REG_BITS-1 downto 0) := "00000110";
|
| 120 |
|
|
constant SM_BR : std_logic_vector(STATUS_REG_BITS-1 downto 0) := "00000000";
|
| 121 |
|
|
constant SM_SGO : std_logic_vector(STATUS_REG_BITS-1 downto 0) := "00000000"; -- set get operations
|
| 122 |
|
|
--constant SM_CMP : std_logic_vector(STATUS_REG_BITS-1 downto 0) := "11111110";
|
| 123 |
|
|
|
| 124 |
|
|
-- data types
|
| 125 |
|
|
constant DT_NONE : std_logic_vector(INSTR_TYPE_BITS-1 downto 0) := "00000";
|
| 126 |
|
|
constant DT_INT : std_logic_vector(INSTR_TYPE_BITS-1 downto 0) := "00001";
|
| 127 |
|
|
constant DT_FLOAT : std_logic_vector(INSTR_TYPE_BITS-1 downto 0) := "00010";
|
| 128 |
|
|
constant DT_CONS : std_logic_vector(INSTR_TYPE_BITS-1 downto 0) := "00011";
|
| 129 |
|
|
constant DT_SNOC : std_logic_vector(INSTR_TYPE_BITS-1 downto 0) := "00100";
|
| 130 |
|
|
constant DT_PTR : std_logic_vector(INSTR_TYPE_BITS-1 downto 0) := "00101";
|
| 131 |
|
|
constant DT_ARRAY : std_logic_vector(INSTR_TYPE_BITS-1 downto 0) := "00110";
|
| 132 |
|
|
constant DT_NIL : std_logic_vector(INSTR_TYPE_BITS-1 downto 0) := "00111";
|
| 133 |
|
|
constant DT_T : std_logic_vector(INSTR_TYPE_BITS-1 downto 0) := "01000";
|
| 134 |
|
|
constant DT_CHAR : std_logic_vector(INSTR_TYPE_BITS-1 downto 0) := "01001";
|
| 135 |
|
|
constant DT_SYMBOL : std_logic_vector(INSTR_TYPE_BITS-1 downto 0) := "01010";
|
| 136 |
|
|
constant DT_FUNCTION : std_logic_vector(INSTR_TYPE_BITS-1 downto 0) := "01011";
|
| 137 |
|
|
|
| 138 |
|
|
|
| 139 |
|
|
constant IMM_SIZE : integer :=18;
|
| 140 |
|
|
-- Constants for internal typing
|
| 141 |
|
|
constant OBJECT_SIZE : integer := 32;
|
| 142 |
|
|
constant DATUM_SIZE : integer := 26;
|
| 143 |
|
|
constant GC_SIZE : integer := 1;
|
| 144 |
|
|
constant TYPE_START : integer := OBJECT_SIZE - INSTR_TYPE_BITS;
|
| 145 |
|
|
constant GC_BIT : integer := 26;
|
| 146 |
|
|
|
| 147 |
|
|
-- Typing ... types, uhrm.
|
| 148 |
|
|
subtype object is std_logic_vector(OBJECT_SIZE - 1 downto 0);
|
| 149 |
|
|
subtype object_type is std_logic_vector(INSTR_TYPE_BITS - 1 downto 0);
|
| 150 |
|
|
subtype object_datum is std_logic_vector(DATUM_SIZE - 1 downto 0);
|
| 151 |
|
|
subtype object_gc is std_logic_vector(GC_SIZE - 1 downto 0);
|
| 152 |
|
|
|
| 153 |
|
|
-- Type constants
|
| 154 |
|
|
constant TYPE_INT : object_type := "00010";
|
| 155 |
|
|
|
| 156 |
|
|
-- Garbage collection constants
|
| 157 |
|
|
constant GC_TRUE : object_gc := "1";
|
| 158 |
|
|
constant GC_FALSE : object_gc := "0";
|
| 159 |
|
|
-- General constants
|
| 160 |
|
|
constant GENERATE_TRACE : boolean := false;
|
| 161 |
|
|
constant MC_ROM_SIZE : integer := 16384; -- instruction mem
|
| 162 |
|
|
constant SCRATCH_MEM_SIZE : integer := 1024; -- size of scratch
|
| 163 |
|
|
|
| 164 |
|
|
|
| 165 |
|
|
-- Instruction word constants
|
| 166 |
|
|
constant IN_OP_SIZE : integer := 6;
|
| 167 |
|
|
constant ALU_FUNCT_SIZE : integer :=6; -- Size of function word for ALU
|
| 168 |
|
|
constant BUS_SIZE : integer := 32;
|
| 169 |
|
|
constant SCRATCH_DEPTH : integer := 10;
|
| 170 |
|
|
|
| 171 |
|
|
-- Clock freq in MHz
|
| 172 |
|
|
constant LEVAL_FREQ : std_logic_vector(7 downto 0) := X"40";
|
| 173 |
|
|
|
| 174 |
|
|
-- Control signal constants
|
| 175 |
|
|
constant PCMUX_NOBRANCH : std_logic_vector(1 downto 0) := "00";
|
| 176 |
|
|
constant PCMUX_STALL : std_logic_vector(1 downto 0) := "01";
|
| 177 |
|
|
constant PCMUX_BRANCH : std_logic_vector(1 downto 0) := "10";
|
| 178 |
|
|
|
| 179 |
|
|
-- Forward constants
|
| 180 |
|
|
constant FWD_REGDATA : std_logic_vector(2 downto 0) := "000";
|
| 181 |
|
|
constant FWD_BRANCH : std_logic_vector(2 downto 0) := "011";
|
| 182 |
|
|
constant FWD_2_IMMEDIATE : std_logic_vector(2 downto 0) := "011";
|
| 183 |
|
|
constant FWD_1_EXMEM_ALURES : std_logic_vector(2 downto 0) := "001";
|
| 184 |
|
|
constant FWD_1_M2WB_ALURES : std_logic_vector(2 downto 0) := "010";
|
| 185 |
|
|
constant FWD_1_M2WB_MEMWRITEDATA : std_logic_vector(2 downto 0) := "100";
|
| 186 |
|
|
|
| 187 |
|
|
constant FWD_2_EXMEM_ALURES : std_logic_vector(2 downto 0) := "001";
|
| 188 |
|
|
constant FWD_2_M2WB_ALURES : std_logic_vector(2 downto 0) := "010";
|
| 189 |
|
|
constant FWD_2_M2WB_MEMWRITEDATA : std_logic_vector(2 downto 0) := "100";
|
| 190 |
|
|
|
| 191 |
|
|
|
| 192 |
|
|
-- constants for CACHE
|
| 193 |
|
|
constant CACHE_LINES : integer := 1024;
|
| 194 |
|
|
constant CACHE_INDEX_BITS : integer := 10;
|
| 195 |
|
|
constant CACHE_TAG_BITS : integer := ADDR_BITS - CACHE_INDEX_BITS; -- 16
|
| 196 |
|
|
constant CACHE_DATA_BITS : integer := WORD_BITS;
|
| 197 |
|
|
constant CACHE_INDEX_POS : integer := 9;
|
| 198 |
|
|
constant CACHE_TAG_START : integer := ADDR_BITS - 1; -- 25
|
| 199 |
|
|
constant CACHE_TAG_END : integer := CACHE_INDEX_POS + 1; -- 10
|
| 200 |
|
|
|
| 201 |
|
|
function sign_extend_18_26(bus_18 : std_logic_vector(17 downto 0))return std_logic_vector;
|
| 202 |
|
|
function mask_flags_match(mask,flags : in std_logic_vector(7 downto 0)) return boolean;
|
| 203 |
|
|
|
| 204 |
|
|
end package;
|
| 205 |
|
|
|
| 206 |
|
|
|
| 207 |
|
|
package body leval2_package is
|
| 208 |
|
|
function sign_extend_18_26(bus_18 : std_logic_vector(17 downto 0))
|
| 209 |
|
|
return std_logic_vector is
|
| 210 |
|
|
variable output : std_logic_vector(25 downto 0);
|
| 211 |
|
|
begin
|
| 212 |
|
|
output(17 downto 0) := bus_18(17 downto 0);
|
| 213 |
|
|
output(25 downto 18) := (others => bus_18(17));
|
| 214 |
|
|
return output;
|
| 215 |
|
|
end function;
|
| 216 |
|
|
|
| 217 |
|
|
function mask_flags_match(mask, flags : in std_logic_vector(7 downto 0)) return boolean is
|
| 218 |
|
|
begin
|
| 219 |
|
|
if (mask(0) = flags(0)) or
|
| 220 |
|
|
(mask(1) = flags(1)) or
|
| 221 |
|
|
(mask(2) = flags(2)) or
|
| 222 |
|
|
(mask(3) = flags(3)) or
|
| 223 |
|
|
(mask(4) = flags(4)) or
|
| 224 |
|
|
(mask(5) = flags(5)) or
|
| 225 |
|
|
(mask(6) = flags(6)) or
|
| 226 |
|
|
(mask(7) = flags(7))
|
| 227 |
|
|
then
|
| 228 |
|
|
return true;
|
| 229 |
|
|
else
|
| 230 |
|
|
return false;
|
| 231 |
|
|
end if;
|
| 232 |
|
|
end function;
|
| 233 |
|
|
|
| 234 |
|
|
end leval2_package;
|