From 14429856872f35d4880fd695a26c1cb695ab633e Mon Sep 17 00:00:00 2001 From: pfaure Date: Wed, 16 Jun 2021 13:24:57 +0200 Subject: [PATCH] Travail en cours, bug adresse tick d'avant --- .../sim_1/new/Test_Etage4_Memoire.vhd | 82 +++++++++----- .../sources_1/new/Etage4_Memoire.vhd | 95 +++++++--------- .../sources_1/new/MemoireDonnees.vhd | 14 ++- Processeur.xpr | 10 +- .../Test_Etage4_Memoire_behav.wcfg | 103 ++++++++++++++++++ 5 files changed, 222 insertions(+), 82 deletions(-) create mode 100644 SimulationsConfig/Test_Etage4_Memoire_behav.wcfg diff --git a/Processeur.srcs/sim_1/new/Test_Etage4_Memoire.vhd b/Processeur.srcs/sim_1/new/Test_Etage4_Memoire.vhd index b9afea5..7f29b36 100644 --- a/Processeur.srcs/sim_1/new/Test_Etage4_Memoire.vhd +++ b/Processeur.srcs/sim_1/new/Test_Etage4_Memoire.vhd @@ -37,34 +37,59 @@ end Test_Etage4_Memoire; architecture Behavioral of Test_Etage4_Memoire is component Etage4_Memoire is - Generic ( Nb_bits : Natural; - Mem_size : Natural; - Instruction_bus_size : Natural; - Bits_Controle_LC : STD_LOGIC_VECTOR; - Bits_Controle_MUX_IN : STD_LOGIC_VECTOR; - Bits_Controle_MUX_OUT : STD_LOGIC_VECTOR); - Port ( CLK : in STD_LOGIC; - RST : in STD_LOGIC; - IN_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); - IN_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); - IN_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0); - OUT_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); - OUT_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); - OUT_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0)); + Generic ( Nb_bits : Natural; -- Taille d'un mot binaire + Mem_size : Natural; -- Taille de la mémoire de donnees (nombre de mots binaires stockables) + Adresse_mem_size : Natural; -- Nombre de bits pour adresser la mémoire de donnees + Instruction_bus_size : Natural; -- Nombre de bits du bus d'instruction (Taille d'un code instruction) + Bits_Controle_LC : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le Link Controler (cf LC.vhd) + Bits_Controle_MUX_IN : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le multiplexer selectionnant A ou B comme adresse (cf MUX.vhd) + Bits_Controle_MUX_IN_EBP : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le multiplexer selectionnant si on doit ajouter ou non EBP à l'adresse (cf MUX.vhd) + Bits_Controle_MUX_OUT : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le multiplexer de sortie (cf MUX.vhd) + Code_Instruction_CALL : STD_LOGIC_VECTOR; -- Numéro de l'instruction CALL + Code_Instruction_RET : STD_LOGIC_VECTOR); -- Numéro de l'instruction RET + Port ( CLK : in STD_LOGIC; -- Clock + RST : in STD_LOGIC; -- Reset + IN_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Entrée de l'opérande A + IN_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Entrée de l'opérande B + IN_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0); -- Entrée de l'instruction + OUT_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Sortie de l'opérande A + OUT_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Sortie de l'opérande B + OUT_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0); -- Sortie de l'instruction + OUT_AddrRetour : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0)); -- Sortie de l'adresse de retour vers l'étage 1 end component; signal my_CLK : STD_LOGIC := '0'; signal my_RST : STD_LOGIC := '1'; signal my_IN_A : STD_LOGIC_VECTOR (7 downto 0) := (others => '0'); signal my_IN_B : STD_LOGIC_VECTOR (7 downto 0) := (others => '0'); - signal my_IN_Instruction : STD_LOGIC_VECTOR (2 downto 0) := (others => '0'); + signal my_IN_Instruction : STD_LOGIC_VECTOR (4 downto 0) := (others => '0'); signal my_OUT_A : STD_LOGIC_VECTOR (7 downto 0) := (others => '0'); signal my_OUT_B : STD_LOGIC_VECTOR (7 downto 0) := (others => '0'); - signal my_OUT_Instruction : STD_LOGIC_VECTOR (2 downto 0) := (others => '0'); + signal my_OUT_Instruction : STD_LOGIC_VECTOR (4 downto 0) := (others => '0'); + signal my_OUT_AddrRetour : STD_LOGIC_VECTOR (7 downto 0) := (others => '0'); - constant Bits_Controle_LC : STD_LOGIC_VECTOR (7 downto 0) := "01111111"; - constant Bits_Controle_MUX_IN : STD_LOGIC_VECTOR (7 downto 0) := "10111111"; - constant Bits_Controle_MUX_OUT : STD_LOGIC_VECTOR (7 downto 0) := "01000000"; + constant Bits_Controle_LC : STD_LOGIC_VECTOR (31 downto 0) := "1111111111" & "1111111001011111111111"; + constant Bits_Controle_MUX_IN : STD_LOGIC_VECTOR (31 downto 0) := "1111111111" & "1101111110101111111111"; + constant Bits_Controle_MUX_IN_EBP : STD_LOGIC_VECTOR (31 downto 0) := "1111111111" & "1001111011001111111111"; + constant Bits_Controle_MUX_OUT : STD_LOGIC_VECTOR (31 downto 0) := "1111111111" & "0000000001010000000000"; + constant Code_Instruction_CALL : STD_LOGIC_VECTOR (4 downto 0) := "10011"; + constant Code_Instruction_RET : STD_LOGIC_VECTOR (4 downto 0) := "10100"; + + constant CNULL : STD_LOGIC_VECTOR (4 downto 0) := "00000"; + constant CWR : STD_LOGIC_VECTOR (4 downto 0) := "01011"; + constant CCALL : STD_LOGIC_VECTOR (4 downto 0) := "10011"; + constant CRET : STD_LOGIC_VECTOR (4 downto 0) := "10100"; + constant C0 : STD_LOGIC_VECTOR (7 downto 0) := "00000000"; + constant C1 : STD_LOGIC_VECTOR (7 downto 0) := "00000001"; + constant C2 : STD_LOGIC_VECTOR (7 downto 0) := "00000010"; + constant C3 : STD_LOGIC_VECTOR (7 downto 0) := "00000011"; + constant C5 : STD_LOGIC_VECTOR (7 downto 0) := "00000101"; + constant C7 : STD_LOGIC_VECTOR (7 downto 0) := "00000111"; + constant C12 : STD_LOGIC_VECTOR (7 downto 0) := "00001100"; + constant C36 : STD_LOGIC_VECTOR (7 downto 0) := "00100100"; + constant C54 : STD_LOGIC_VECTOR (7 downto 0) := "00110110"; + constant C77 : STD_LOGIC_VECTOR (7 downto 0) := "01001101"; + constant C100 : STD_LOGIC_VECTOR (7 downto 0) := "01100100"; constant CLK_period : time := 10 ns; @@ -72,11 +97,15 @@ begin instance : Etage4_Memoire generic map( Nb_bits => 8, - Mem_size => 256, - Instruction_bus_size => 3, + Mem_size => 16, + Adresse_mem_size => 4, + Instruction_bus_size => 5, Bits_Controle_LC => Bits_Controle_LC, Bits_Controle_MUX_IN => Bits_Controle_MUX_IN, - Bits_Controle_MUX_OUT => Bits_Controle_MUX_OUT) + Bits_Controle_MUX_IN_EBP => Bits_Controle_MUX_IN_EBP, + Bits_Controle_MUX_OUT => Bits_Controle_MUX_OUT, + Code_Instruction_CALL => Code_Instruction_CALL, + Code_Instruction_RET => Code_Instruction_RET) port map( CLK => my_CLK, RST => my_RST, IN_A => my_IN_A, @@ -84,7 +113,8 @@ begin IN_Instruction => my_IN_Instruction, OUT_A => my_OUT_A, OUT_B => my_OUT_B, - OUT_Instruction => my_OUT_Instruction); + OUT_Instruction => my_OUT_Instruction, + OUT_AddrRetour => my_OUT_AddrRetour); CLK_process :process begin @@ -96,9 +126,9 @@ begin process begin - my_IN_A <= "01011111" after 0 ns, "11111111" after 124 ns; - my_IN_B <= "10100110" after 0 ns, "01011111" after 124 ns; - my_IN_Instruction <= "000" after 0 ns, "001" after 10 ns, "010" after 20 ns, "011" after 30 ns, "100" after 40 ns, "101" after 50 ns, "110" after 60 ns, "111" after 70 ns, "000" after 80 ns, "110" after 100 ns, "111" after 110 ns, "110" after 120 ns; + my_IN_A <= C0 after 0 ns, C0 after 5 ns, C1 after 15 ns, C2 after 25 ns, C77 after 35 ns, C0 after 45 ns, C54 after 55 ns, C0 after 65 ns, C0 after 75 ns; + my_IN_B <= C0 after 0 ns, C36 after 5 ns, C5 after 15 ns, C7 after 25 ns, C3 after 35 ns, C12 after 45 ns, C1 after 55 ns, C100 after 65 ns, C0 after 75 ns; + my_IN_Instruction <= CNULL after 0 ns, CWR after 5 ns, CWR after 15 ns, CWR after 25 ns, CCALL after 35 ns, CWR after 45 ns, CCALL after 55 ns, CWR after 65 ns, CRET after 75 ns, CRET after 85 ns, CNULL after 95 ns; my_RST <= '0' after 125 ns; wait; end process; diff --git a/Processeur.srcs/sources_1/new/Etage4_Memoire.vhd b/Processeur.srcs/sources_1/new/Etage4_Memoire.vhd index 93afac9..0c12e4d 100644 --- a/Processeur.srcs/sources_1/new/Etage4_Memoire.vhd +++ b/Processeur.srcs/sources_1/new/Etage4_Memoire.vhd @@ -29,8 +29,6 @@ entity Etage4_Memoire is Mem_size : Natural; -- Taille de la mémoire de donnees (nombre de mots binaires stockables) Adresse_mem_size : Natural; -- Nombre de bits pour adresser la mémoire de donnees Instruction_bus_size : Natural; -- Nombre de bits du bus d'instruction (Taille d'un code instruction) - Mem_EBP_size : Natural; -- Taille de la mémoire du contexte (profondeur d'appel maximale) - Adresse_size_mem_EBP : Natural; -- Nombre de bits pour adresser la mémoire de contexte Bits_Controle_LC : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le Link Controler (cf LC.vhd) Bits_Controle_MUX_IN : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le multiplexer selectionnant A ou B comme adresse (cf MUX.vhd) Bits_Controle_MUX_IN_EBP : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le multiplexer selectionnant si on doit ajouter ou non EBP à l'adresse (cf MUX.vhd) @@ -44,7 +42,8 @@ entity Etage4_Memoire is IN_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0); -- Entrée de l'instruction OUT_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Sortie de l'opérande A OUT_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Sortie de l'opérande B - OUT_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0)); -- Sortie de l'instruction + OUT_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0); -- Sortie de l'instruction + OUT_AddrRetour : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0)); -- Sortie de l'adresse de retour vers l'étage 1 end Etage4_Memoire; architecture Structural of Etage4_Memoire is @@ -52,26 +51,18 @@ architecture Structural of Etage4_Memoire is Generic (Nb_bits : Natural; Addr_size : Natural; Mem_size : Natural); - Port ( Addr : in STD_LOGIC_VECTOR (Addr_size-1 downto 0); - RW : in STD_LOGIC; - D_IN : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0); - RST : in STD_LOGIC; - CLK : in STD_LOGIC; - D_OUT : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0')); - end component; - - component MemoireAdressesRetour is - Generic (Nb_bits : Natural; - Addr_size : Natural; - Mem_size : Natural); - Port ( R : in STD_LOGIC; - W : in STD_LOGIC; - D_IN : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0); - RST : in STD_LOGIC; - CLK : in STD_LOGIC; - D_OUT : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0'); - E : out STD_LOGIC; - F : out STD_LOGIC); + Port ( Addr : in STD_LOGIC_VECTOR (Addr_size-1 downto 0); -- L'adresse a laquelle il faut agir + RW : in STD_LOGIC; -- Ce qu'il faut faire ('1' -> Read, '0' -> Write) + D_IN : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0); -- Data a ecrire (si RW = 0) + CALL : in STD_LOGIC; -- '1' -> CALL en cours + IN_EBP : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0); -- Valeur d'EBP à stocker en cas de CALL + IN_AddrRet : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0); -- Valeur d'@ de retour à stocker en cas de CALL + RET : in STD_LOGIC; -- '1' -> RET en cours + OUT_EBP : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0'); -- Valeur d'EBP à renvoyer en cas de RET + OUT_AddrRet : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0'); -- Valeur d'@ de retour à renvoyer en cas de RET + RST : in STD_LOGIC; -- Reset + CLK : in STD_LOGIC; -- Clock + D_OUT : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0')); -- Sortie de la mémoire end component; component LC is @@ -94,7 +85,9 @@ architecture Structural of Etage4_Memoire is signal EBP : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- EBP (offset à ajouter à l'adresse) + signal Last_EBP : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0'); -- Ancien EBP, valeur récupérée en mémoire lors d'un RET signal New_EBP : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- Nouvelle valeur d'EBP, a stocker lors d'un CALL (Cf fonctionnement MemoireAdressesRetour.vhd) + signal IN_EBP : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0'); -- EBP à stocker ne mémoire (ajout de 0) signal Addr_MemoireDonnees : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- Adresse entrante dans le composant de mémoire de donnees signal IN_Addr_MemoireDonnees : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- Sortie du mux de choix d'adresse entre A et B @@ -106,11 +99,9 @@ architecture Structural of Etage4_Memoire is signal intern_OUT_B : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0'); -- Signal interne - -- Signaux de la memoire de contexte - signal R_Aux : STD_LOGIC := '0'; - signal W_Aux : STD_LOGIC := '0'; - signal E : STD_LOGIC; - signal F : STD_LOGIC; + -- Signaux de contrôle de la mémoire + signal CALL_Aux : STD_LOGIC := '0'; + signal RET_Aux : STD_LOGIC := '0'; begin @@ -152,27 +143,18 @@ begin generic map (Nb_bits => Nb_bits, Addr_size => Adresse_mem_size, Mem_size => Mem_size) - port map ( Addr => Addr_MemoireDonnees, - RW => Commande_MemoireDonnees(0), - D_IN => IN_B, - RST => RST, - CLK => CLK, - D_OUT => Sortie_MemoireDonnees); - - instance_MemoireEBP : MemoireAdressesRetour - generic map (Nb_bits => Adresse_mem_size, - Addr_size => Adresse_size_mem_EBP, - Mem_size => Mem_EBP_size - ) - port map ( R => R_Aux, - W => W_Aux, - D_IN => New_EBP, - RST => RST, - CLK => CLK, - D_OUT => EBP, - E => E, - F => F - ); + port map (Addr => Addr_MemoireDonnees, + RW => Commande_MemoireDonnees(0), + D_IN => IN_B, + CALL => CALL_Aux, + IN_EBP => IN_EBP, + IN_AddrRet => IN_A, + RET => RET_Aux, + OUT_EBP => Last_EBP, + OUT_AddrRet => OUT_AddrRetour, + RST => RST, + CLK => CLK, + D_OUT => Sortie_MemoireDonnees); OUT_A <= (others => '0') when RST = '0' else IN_A; @@ -181,12 +163,19 @@ begin OUT_Instruction <= (others => '0') when RST = '0' else IN_Instruction; - -- Controle de la mémoire de contexte (ici aussi un LC aurait été disproportionné) - R_Aux <= '1' when IN_Instruction = Code_Instruction_RET else + -- Controle de la gestion des appels de fonctions (ici aussi un LC aurait été disproportionné) + RET_Aux <= '1' when IN_Instruction = Code_Instruction_RET else '0'; - W_Aux <= '1' when IN_Instruction = Code_Instruction_CALL else + CALL_Aux <= '1' when IN_Instruction = Code_Instruction_CALL else '0'; + New_EBP <= EBP + IN_B (Adresse_mem_size - 1 downto 0) + 2; + EBP <= New_EBP when CLK'event and CLK='1' and IN_Instruction = Code_Instruction_CALL else + Last_EBP (Adresse_mem_size - 1 downto 0) when CLK'event and CLK='1' and IN_Instruction = Code_Instruction_RET else + (others => '0') when RST = '0' else + EBP; + IN_EBP <= (Nb_bits - 1 downto Adresse_mem_size => '0') & EBP; + Addr_MemoireDonnees_EBP <= IN_Addr_MemoireDonnees + EBP; - New_EBP <= EBP + IN_B (Adresse_mem_size - 1 downto 0); + end Structural; diff --git a/Processeur.srcs/sources_1/new/MemoireDonnees.vhd b/Processeur.srcs/sources_1/new/MemoireDonnees.vhd index adf035d..2c71dd1 100644 --- a/Processeur.srcs/sources_1/new/MemoireDonnees.vhd +++ b/Processeur.srcs/sources_1/new/MemoireDonnees.vhd @@ -23,6 +23,12 @@ entity MemoireDonnees is Port ( Addr : in STD_LOGIC_VECTOR (Addr_size-1 downto 0); -- L'adresse a laquelle il faut agir RW : in STD_LOGIC; -- Ce qu'il faut faire ('1' -> Read, '0' -> Write) D_IN : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0); -- Data a ecrire (si RW = 0) + CALL : in STD_LOGIC; -- '1' -> CALL en cours + IN_EBP : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0); -- Valeur d'EBP à stocker en cas de CALL + IN_AddrRet : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0); -- Valeur d'@ de retour à stocker en cas de CALL + RET : in STD_LOGIC; -- '1' -> RET en cours + OUT_EBP : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0'); -- Valeur d'EBP à renvoyer en cas de RET + OUT_AddrRet : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0'); -- Valeur d'@ de retour à renvoyer en cas de RET RST : in STD_LOGIC; -- Reset CLK : in STD_LOGIC; -- Clock D_OUT : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0')); -- Sortie de la mémoire @@ -37,7 +43,13 @@ begin if (RST = '0') then MEMORY <= (others => '0'); else - if (RW = '0') then + if (CALL = '1') then + MEMORY (((to_integer(unsigned(Addr)) + 1) * Nb_bits - 1) downto Nb_bits * to_integer(unsigned(Addr))) <= IN_EBP; + MEMORY (((to_integer(unsigned(Addr)) + 2) * Nb_bits - 1) downto Nb_bits * (to_integer(unsigned(Addr)) + 1)) <= IN_AddrRet; + elsif (RET = '1') then + OUT_EBP <= MEMORY (((to_integer(unsigned(Addr)) - 1) * Nb_bits - 1) downto Nb_bits * (to_integer(unsigned(Addr)) - 2)); + OUT_AddrRet <= MEMORY ((to_integer(unsigned(Addr)) * Nb_bits - 1) downto Nb_bits * (to_integer(unsigned(Addr)) - 1)); + elsif (RW = '0') then MEMORY (((to_integer(unsigned(Addr)) + 1) * Nb_bits - 1) downto Nb_bits * to_integer(unsigned(Addr))) <= D_IN; end if; end if; diff --git a/Processeur.xpr b/Processeur.xpr index 98f1206..9369af6 100644 --- a/Processeur.xpr +++ b/Processeur.xpr @@ -32,7 +32,7 @@