-- yasep_utils.vhdl -- created mar. févr. 21 18:10:32 CET 2012 by whygee@f-cpu.org -- version lun. juin 10 07:19:19 CEST 2013 addded sulv2txt -- -- This file belongs to the YASEP project and is distributed under the -- AGPLv3 (or later) license. See http://yasep.org/license/agpl.txt -- -- defines non-configurable features of the core, see yasep_def.vhdl for the configurable data. -- It also provides small convenience functions to ease simulation and verification. Library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; library work; use work.yasep_definitions.all; package yasep_utils is -- To be used as "R_GROUP'range" subtype R_GROUP is std_logic_vector( 4 downto 2); subtype R_FUNCTION is std_logic_vector( 7 downto 5); subtype R_OPCODE is std_logic_vector( 7 downto 2); subtype R_SND is std_logic_vector(11 downto 8); subtype R_SI4 is std_logic_vector(15 downto 12); constant INDEX_PTR1 : integer := 16; -- unused yet, will serve for pointer updates constant INDEX_aux : integer := 1+16; subtype R_PTR2 is std_logic_vector(20 downto 18); constant INDEX_neg : integer := 5+16; subtype R_COND_TYPE is std_logic_vector(23 downto 22); subtype R_DST is std_logic_vector(27 downto 24); subtype R_COND_SRC is std_logic_vector(31 downto 28); constant FORM_RR : SLV2 := "00"; constant FORM_RI4 : SLV2 := "10"; constant FORM_RRI16 : SLV2 := "01"; constant FORM_EXT : SLV2 := "11"; constant COND_ZERO : SLV2 := "00"; constant COND_BIT : SLV2 := "01"; constant COND_LSB : SLV2 := "10"; constant COND_MSB : SLV2 := "11"; function SLVAI_to_SLVY(v: SLVAI) return SLVY; function safe_to_integer(u:std_logic_vector) return integer; function sulv2txt(s : std_ulogic_vector) return string; function SLV4_to_Hex(s:SLV4) return character; function SLV_to_Hex(s:std_logic_vector) return string; function assemble(form: SLV2; opcode:SLV6; SND: SLV4; SI4: SLV4; IMM16: SLV16 := "0000000000000000") return SLV32; function assemble_x(aux:std_logic; opcode:SLV6; SND: SLV4; SI4: SLV4; DST: SLV4; cond:SLV4:="0000"; func:SLV2:="00"; neg:std_logic := '0' ) return SLV32; end yasep_utils; package body yasep_utils is -- adapte le PC à la largeur des mots function SLVAI_to_SLVY(v: SLVAI) return SLVY is variable r:SLVY := (SLVY'range=>'0'); begin r(SLVAI'range) := v; return r; end; function safe_to_integer(u:std_logic_vector) return integer is begin if Is_X(u) then return 0; else return to_integer(unsigned(u)); end if; end; function sulv2txt(s : std_ulogic_vector) return string is variable t : string(s'range); variable u : string(3 downto 1); begin for i in s'range loop u := std_ulogic'image(s(i)); t(i) := u(2); end loop; return t; end sulv2txt; function SLV4_to_Hex(s:SLV4) return character is begin case s is when "0000" => return '0'; when "0001" => return '1'; when "0010" => return '2'; when "0011" => return '3'; when "0100" => return '4'; when "0101" => return '5'; when "0110" => return '6'; when "0111" => return '7'; when "1000" => return '8'; when "1001" => return '9'; when "1010" => return 'A'; when "1011" => return 'B'; when "1100" => return 'C'; when "1101" => return 'D'; when "1110" => return 'E'; when "1111" => return 'F'; when others => return '?'; end case; end; function SLV_to_Hex(s:std_logic_vector) return string is variable u:std_logic_vector(s'length+3 downto 0); variable t: string((s'length-1)/4 downto 0); variable i: integer:= 0; variable j: integer:= 0; begin u:= "0000" & s; while (i < s'length) loop t(j) := SLV4_to_Hex(u(i+3 downto i)); i := i+4; j := j+1; end loop; return t; end; function assemble(form: SLV2; opcode:SLV6; SND: SLV4; SI4: SLV4; IMM16: SLV16 := "0000000000000000") return SLV32 is variable t: SLV32 := IMM16 & SI4 & SND & opcode & form; begin return t; end; function assemble_x(aux:std_logic; opcode:SLV6; SND: SLV4; SI4: SLV4; DST: SLV4; cond:SLV4:="0000"; func:SLV2:="00"; neg:std_logic := '0' ) return SLV32 is variable t: SLV32 := (31 downto 0=>'0'); begin t(1 downto 0) := FORM_EXT; t(R_OPCODE'range) := opcode; t(R_SND'range) := SND; t(R_SI4'range) := SI4; t(INDEX_aux) := aux; t(INDEX_neg) := neg; t(R_COND_TYPE'range) := func; t(R_DST'range) := DST; t(R_COND_SRC'range) := cond; return t; end; end yasep_utils;