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 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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; -- Taille d'un mot en mémoire
  49. Addr_size : Natural; -- Nombre de bits nécessaires a l'adressage de la mémoire
  50. Mem_size : Natural); -- Nombre de mot stockables
  51. Port ( Addr : in STD_LOGIC_VECTOR (Addr_size-1 downto 0); -- L'adresse a laquelle il faut agir
  52. RW : in STD_LOGIC; -- Ce qu'il faut faire ('1' -> Read, '0' -> Write)
  53. D_IN : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0); -- Data a ecrire (si RW = 0)
  54. CALL : in STD_LOGIC; -- '1' -> CALL en cours
  55. IN_EBP : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0); -- Valeur d'EBP à stocker en cas de CALL
  56. IN_AddrRet : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0); -- Valeur d'@ de retour à stocker en cas de CALL
  57. RET : in STD_LOGIC; -- '1' -> RET en cours
  58. OUT_EBP : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0'); -- Valeur d'EBP à renvoyer en cas de RET
  59. OUT_AddrRet : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0'); -- Valeur d'@ de retour à renvoyer en cas de RET
  60. RST : in STD_LOGIC; -- Reset
  61. CLK : in STD_LOGIC; -- Clock
  62. D_OUT : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0')); -- Sortie de la mémoire
  63. end component;
  64. component MemoireAdressesRetour is
  65. Generic (Nb_bits : Natural;
  66. Addr_size : Natural;
  67. Mem_size : Natural);
  68. Port ( R : in STD_LOGIC;
  69. W : in STD_LOGIC;
  70. D_IN : in STD_LOGIC_VECTOR (Nb_bits-1 downto 0);
  71. RST : in STD_LOGIC;
  72. CLK : in STD_LOGIC;
  73. D_OUT : out STD_LOGIC_VECTOR (Nb_bits-1 downto 0) := (others => '0');
  74. E : out STD_LOGIC;
  75. F : out STD_LOGIC);
  76. end component;
  77. component LC is
  78. Generic (Instruction_Vector_Size : Natural;
  79. Command_size : Natural;
  80. Bits_Controle : STD_LOGIC_VECTOR);
  81. Port ( Instruction : in STD_LOGIC_VECTOR (Instruction_Vector_Size - 1 downto 0);
  82. Commande : out STD_LOGIC_VECTOR (Command_size - 1 downto 0));
  83. end component;
  84. component MUX is
  85. Generic (Nb_bits : Natural;
  86. Instruction_Vector_Size : Natural;
  87. Bits_Controle : STD_LOGIC_VECTOR);
  88. Port ( Instruction : in STD_LOGIC_VECTOR (Instruction_Vector_Size - 1 downto 0);
  89. IN1 : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  90. IN2 : in STD_LOGIC_VECTOR (Nb_bits - 1 downto 0);
  91. OUTPUT : out STD_LOGIC_VECTOR (Nb_bits - 1 downto 0));
  92. end component;
  93. signal EBP : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- EBP (offset à ajouter à l'adresse)
  94. 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)
  95. signal Addr_MemoireDonnees : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- Adresse entrante dans le composant de mémoire de donnees
  96. 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
  97. signal Addr_MemoireDonnees_EBP : STD_LOGIC_VECTOR (Adresse_mem_size - 1 downto 0) := (others => '0'); -- Adresse avec EBP ajouté (IN_Addr_MemoireDonnees + BP)
  98. signal Commande_MemoireDonnees : STD_LOGIC_VECTOR (0 downto 0) := "0"; -- Sortie du Link Controler, signal de commande de la mémoire
  99. signal Sortie_MemoireDonnees : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0'); -- Sortie de la mémoire (a multiplexer)
  100. signal intern_OUT_B : STD_LOGIC_VECTOR (Nb_bits - 1 downto 0) := (others => '0'); -- Signal interne
  101. -- Signaux de la memoire de contexte
  102. signal R_Aux : STD_LOGIC := '0';
  103. signal W_Aux : STD_LOGIC := '0';
  104. signal E : STD_LOGIC;
  105. signal F : STD_LOGIC;
  106. -- Signaux inutiles
  107. signal OUT_EBP : STD_LOGIC_VECTOR (Nb_bits-1 downto 0);
  108. signal OUT_AddrRet : STD_LOGIC_VECTOR (Nb_bits-1 downto 0);
  109. begin
  110. instance_LC : LC -- Link controleur sur la mémoire de donnees
  111. generic map (Instruction_Vector_Size => Instruction_bus_size,
  112. Command_size => 1,
  113. Bits_Controle => Bits_Controle_LC)
  114. port map ( Instruction => IN_Instruction,
  115. Commande => Commande_MemoireDonnees);
  116. instance_MUX_IN : MUX -- Multiplexeur selectionnant A ou B pour adresse
  117. generic map (Nb_bits => Adresse_mem_size,
  118. Instruction_Vector_Size => Instruction_bus_size,
  119. Bits_Controle => Bits_Controle_MUX_IN)
  120. port map ( Instruction => IN_Instruction,
  121. IN1 => IN_A (Adresse_mem_size - 1 downto 0),
  122. IN2 => IN_B (Adresse_mem_size - 1 downto 0),
  123. OUTPUT => IN_Addr_MemoireDonnees);
  124. instance_MUX_IN_EBP : MUX -- Multiplexeur selectionnant l'adresse plus EBP ou l'adresse de base
  125. generic map (Nb_bits => Adresse_mem_size,
  126. Instruction_Vector_Size => Instruction_bus_size,
  127. Bits_Controle => Bits_Controle_MUX_IN_EBP)
  128. port map ( Instruction => IN_Instruction,
  129. IN1 => IN_Addr_MemoireDonnees,
  130. IN2 => Addr_MemoireDonnees_EBP,
  131. OUTPUT => Addr_MemoireDonnees);
  132. instance_MUX_OUT : MUX -- Multiplexeur selectionnant la sortie de l'étage (sur B)
  133. generic map (Nb_bits => Nb_bits,
  134. Instruction_Vector_Size => Instruction_bus_size,
  135. Bits_Controle => Bits_Controle_MUX_OUT)
  136. port map ( Instruction => IN_Instruction,
  137. IN1 => Sortie_MemoireDonnees,
  138. IN2 => IN_B,
  139. OUTPUT => intern_OUT_B);
  140. instance_MemoireDonnees : MemoireDonnees
  141. generic map (Nb_bits => Nb_bits,
  142. Addr_size => Adresse_mem_size,
  143. Mem_size => Mem_size)
  144. port map ( Addr => Addr_MemoireDonnees,
  145. RW => Commande_MemoireDonnees(0),
  146. D_IN => IN_B,
  147. CALL => '0',
  148. IN_EBP => (others => '0'),
  149. IN_AddrRet => (others => '0'),
  150. RET => '0',
  151. OUT_EBP => OUT_EBP,
  152. OUT_AddrRet => OUT_AddrRet,
  153. RST => RST,
  154. CLK => CLK,
  155. D_OUT => Sortie_MemoireDonnees);
  156. instance_MemoireEBP : MemoireAdressesRetour
  157. generic map (Nb_bits => Adresse_mem_size,
  158. Addr_size => Adresse_size_mem_EBP,
  159. Mem_size => Mem_EBP_size
  160. )
  161. port map ( R => R_Aux,
  162. W => W_Aux,
  163. D_IN => New_EBP,
  164. RST => RST,
  165. CLK => CLK,
  166. D_OUT => EBP,
  167. E => E,
  168. F => F
  169. );
  170. OUT_A <= (others => '0') when RST = '0' else
  171. IN_A;
  172. OUT_B <= (others => '0') when RST = '0' else
  173. intern_OUT_B;
  174. OUT_Instruction <= (others => '0') when RST = '0' else
  175. IN_Instruction;
  176. -- Controle de la mémoire de contexte (ici aussi un LC aurait été disproportionné)
  177. R_Aux <= '1' when IN_Instruction = Code_Instruction_RET else
  178. '0';
  179. W_Aux <= '1' when IN_Instruction = Code_Instruction_CALL else
  180. '0';
  181. Addr_MemoireDonnees_EBP <= IN_Addr_MemoireDonnees + EBP;
  182. New_EBP <= EBP + IN_B (Adresse_mem_size - 1 downto 0);
  183. end Structural;