No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Etage4_Memoire.vhd 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. ----------------------------------------------------------------------------------
  2. -- Company: INSA-Toulouse
  3. -- Engineer: Paul Faure
  4. --
  5. -- Create Date: 18.04.2021 21:19:41
  6. -- Module Name: Etage4_Memoire - Structural
  7. -- Project Name: Processeur sécurisé
  8. -- Target Devices: Basys 3 ARTIX7
  9. -- Tool Versions: Vivado 2016.4
  10. --
  11. -- Description: Etage 4 du processeur
  12. -- - Gestion de la mémoire
  13. -- - Gestion de la sauvegarde du contexte lors des appels de fonction
  14. --
  15. -- Dependencies:
  16. -- - MemoireDonnees
  17. -- - MemoireAdressesRetour
  18. -- - LC
  19. -- - MUX
  20. ----------------------------------------------------------------------------------
  21. library IEEE;
  22. use IEEE.STD_LOGIC_1164.ALL;
  23. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  24. entity Etage4_Memoire is
  25. Generic ( Nb_bits : Natural; -- Taille d'un mot binaire
  26. Mem_size : Natural; -- Taille de la mémoire de donnees (nombre de mots binaires stockables)
  27. Adresse_mem_size : Natural; -- Nombre de bits pour adresser la mémoire de donnees
  28. Instruction_bus_size : Natural; -- Nombre de bits du bus d'instruction (Taille d'un code instruction)
  29. Mem_EBP_size : Natural; -- Taille de la mémoire du contexte (profondeur d'appel maximale)
  30. Adresse_size_mem_EBP : Natural; -- Nombre de bits pour adresser la mémoire de contexte
  31. Bits_Controle_LC : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le Link Controler (cf LC.vhd)
  32. Bits_Controle_MUX_IN : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le multiplexer selectionnant A ou B comme adresse (cf MUX.vhd)
  33. 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)
  34. Bits_Controle_MUX_OUT : STD_LOGIC_VECTOR; -- Vecteur de bit controlant le multiplexer de sortie (cf MUX.vhd)
  35. Code_Instruction_CALL : STD_LOGIC_VECTOR; -- Numéro de l'instruction CALL
  36. Code_Instruction_RET : STD_LOGIC_VECTOR); -- Numéro de l'instruction RET
  37. Port ( CLK : in STD_LOGIC; -- Clock
  38. RST : in STD_LOGIC; -- Reset
  39. IN_A : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Entrée de l'opérande A
  40. IN_B : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Entrée de l'opérande B
  41. IN_Instruction : in STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0); -- Entrée de l'instruction
  42. OUT_A : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Sortie de l'opérande A
  43. OUT_B : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0); -- Sortie de l'opérande B
  44. OUT_Instruction : out STD_LOGIC_VECTOR (Instruction_bus_size - 1 downto 0)); -- Sortie de l'instruction
  45. end Etage4_Memoire;
  46. architecture Structural of Etage4_Memoire is
  47. component MemoireDonnees is
  48. Generic (Nb_bits : Natural;
  49. Addr_size : Natural;
  50. Mem_size : Natural);
  51. Port ( Addr : in STD_LOGIC_VECTOR (Addr_size-1 downto 0);
  52. RW : in STD_LOGIC;
  53. D_IN : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0);
  54. RST : in STD_LOGIC;
  55. CLK : in STD_LOGIC;
  56. D_OUT : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0'));
  57. end component;
  58. component MemoireAdressesRetour is
  59. Generic (Nb_bits : Natural;
  60. Addr_size : Natural;
  61. Mem_size : Natural);
  62. Port ( R : in STD_LOGIC;
  63. W : in STD_LOGIC;
  64. D_IN : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0);
  65. RST : in STD_LOGIC;
  66. CLK : in STD_LOGIC;
  67. D_OUT : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0');
  68. E : out STD_LOGIC;
  69. F : out STD_LOGIC);
  70. end component;
  71. component LC is
  72. Generic (Instruction_Vector_Size : Natural;
  73. Command_size : Natural;
  74. Bits_Controle : STD_LOGIC_VECTOR);
  75. Port ( Instruction : in STD_LOGIC_VECTOR (Instruction_Vector_Size - 1 downto 0);
  76. Commande : out STD_LOGIC_VECTOR (Command_size - 1 downto 0));
  77. end component;
  78. component MUX is
  79. Generic (Nb_bits : Natural;
  80. Instruction_Vector_Size : Natural;
  81. Bits_Controle : STD_LOGIC_VECTOR);
  82. Port ( Instruction : in STD_LOGIC_VECTOR (Instruction_Vector_Size - 1 downto 0);
  83. IN1 : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  84. IN2 : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  85. OUTPUT : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0));
  86. end component;
  87. signal EBP : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- EBP (offset à ajouter à l'adresse)
  88. 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)
  89. signal Addr_MemoireDonnees : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- Adresse entrante dans le composant de mémoire de donnees
  90. 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
  91. signal Addr_MemoireDonnees_EBP : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- Adresse avec EBP ajouté (IN_Addr_MemoireDonnees + BP)
  92. signal Commande_MemoireDonnees : STD_LOGIC_VECTOR (0 downto 0) := "0"; -- Sortie du Link Controler, signal de commande de la mémoire
  93. signal Sortie_MemoireDonnees : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0'); -- Sortie de la mémoire (a multiplexer)
  94. signal intern_OUT_B : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0'); -- Signal interne
  95. -- Signaux de la memoire de contexte
  96. signal R_Aux : STD_LOGIC := '0';
  97. signal W_Aux : STD_LOGIC := '0';
  98. signal E : STD_LOGIC;
  99. signal F : STD_LOGIC;
  100. begin
  101. instance_LC : LC -- Link controleur sur la mémoire de donnees
  102. generic map (Instruction_Vector_Size => Instruction_bus_size,
  103. Command_size => 1,
  104. Bits_Controle => Bits_Controle_LC)
  105. port map ( Instruction => IN_Instruction,
  106. Commande => Commande_MemoireDonnees);
  107. instance_MUX_IN : MUX -- Multiplexeur selectionnant A ou B pour adresse
  108. generic map (Nb_bits => Adresse_mem_size,
  109. Instruction_Vector_Size => Instruction_bus_size,
  110. Bits_Controle => Bits_Controle_MUX_IN)
  111. port map ( Instruction => IN_Instruction,
  112. IN1 => IN_A (Adresse_mem_size - 1 downto 0),
  113. IN2 => IN_B (Adresse_mem_size - 1 downto 0),
  114. OUTPUT => IN_Addr_MemoireDonnees);
  115. instance_MUX_IN_EBP : MUX -- Multiplexeur selectionnant l'adresse plus EBP ou l'adresse de base
  116. generic map (Nb_bits => Adresse_mem_size,
  117. Instruction_Vector_Size => Instruction_bus_size,
  118. Bits_Controle => Bits_Controle_MUX_IN_EBP)
  119. port map ( Instruction => IN_Instruction,
  120. IN1 => IN_Addr_MemoireDonnees,
  121. IN2 => Addr_MemoireDonnees_EBP,
  122. OUTPUT => Addr_MemoireDonnees);
  123. instance_MUX_OUT : MUX -- Multiplexeur selectionnant la sortie de l'étage (sur B)
  124. generic map (Nb_bits => Nb_bits,
  125. Instruction_Vector_Size => Instruction_bus_size,
  126. Bits_Controle => Bits_Controle_MUX_OUT)
  127. port map ( Instruction => IN_Instruction,
  128. IN1 => Sortie_MemoireDonnees,
  129. IN2 => IN_B,
  130. OUTPUT => intern_OUT_B);
  131. instance_MemoireDonnees : MemoireDonnees
  132. generic map (Nb_bits => Nb_bits,
  133. Addr_size => Adresse_mem_size,
  134. Mem_size => Mem_size)
  135. port map ( Addr => Addr_MemoireDonnees,
  136. RW => Commande_MemoireDonnees(0),
  137. D_IN => IN_B,
  138. RST => RST,
  139. CLK => CLK,
  140. D_OUT => Sortie_MemoireDonnees);
  141. instance_MemoireEBP : MemoireAdressesRetour
  142. generic map (Nb_bits => Adresse_mem_size,
  143. Addr_size => Adresse_size_mem_EBP,
  144. Mem_size => Mem_EBP_size
  145. )
  146. port map ( R => R_Aux,
  147. W => W_Aux,
  148. D_IN => New_EBP,
  149. RST => RST,
  150. CLK => CLK,
  151. D_OUT => EBP,
  152. E => E,
  153. F => F
  154. );
  155. OUT_A <= (others => '0') when RST = '0' else
  156. IN_A;
  157. OUT_B <= (others => '0') when RST = '0' else
  158. intern_OUT_B;
  159. OUT_Instruction <= (others => '0') when RST = '0' else
  160. IN_Instruction;
  161. -- Controle de la mémoire de contexte (ici aussi un LC aurait été disproportionné)
  162. R_Aux <= '1' when IN_Instruction = Code_Instruction_RET else
  163. '0';
  164. W_Aux <= '1' when IN_Instruction = Code_Instruction_CALL else
  165. '0';
  166. Addr_MemoireDonnees_EBP <= IN_Addr_MemoireDonnees + EBP;
  167. New_EBP <= EBP + IN_B (Adresse_mem_size - 1 downto 0);
  168. end Structural;