core_pkg.vhd 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.numeric_std.all;
  4. use work.mem_pkg.all;
  5. package core_pkg is
  6. -- width of an instruction word
  7. constant INSTR_WIDTH_BITS : integer := 5;
  8. constant INSTR_WIDTH : integer := 2**INSTR_WIDTH_BITS;
  9. -- size of instruction memory
  10. constant PC_WIDTH : integer := ADDR_WIDTH+2;
  11. -- regfile properties
  12. constant REG_BITS : integer := 5;
  13. constant REG_COUNT : integer := 2**REG_BITS;
  14. -- to make things easier, we make CPU data types identical to memory types.
  15. subtype data_type is mem_data_type;
  16. -- types for the interfaces
  17. subtype pc_type is std_logic_vector(PC_WIDTH-1 downto 0);
  18. subtype instr_type is std_logic_vector(INSTR_WIDTH-1 downto 0);
  19. subtype reg_adr_type is std_logic_vector(REG_BITS-1 downto 0);
  20. -- useful constants
  21. constant ZERO_REG : reg_adr_type := (others => '0');
  22. constant ZERO_DATA : data_type := (others => '0');
  23. constant ZERO_PC : pc_type := (others => '0');
  24. constant NOP_INST : instr_type := X"00000013";
  25. pure function to_data_type(pc : pc_type) return data_type;
  26. pure function to_pc_type(data : data_type) return pc_type;
  27. end package;
  28. package body core_pkg is
  29. pure function to_data_type(pc : pc_type) return data_type is
  30. begin
  31. return std_logic_vector(resize(unsigned(pc), data_type'length));
  32. end function;
  33. pure function to_pc_type(data : data_type) return pc_type is
  34. begin
  35. return std_logic_vector(resize(unsigned(data), pc_type'length));
  36. end function;
  37. end package body;